{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(\"data/table.csv\",index_col = 'ID')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "索引  loc标签索引(包含左右端点) 行索引 loc后面接[]\n",
    "loc中能传入的只有布尔列表和索引子集构成的列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "School          S_1\n",
       "Class           C_1\n",
       "Gender            M\n",
       "Address    street_2\n",
       "Height          186\n",
       "Weight           82\n",
       "Math           87.2\n",
       "Physics          B+\n",
       "Name: 1103, dtype: object"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[1103]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>School</th>\n",
       "      <th>Class</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Address</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1103</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_2</td>\n",
       "      <td>186</td>\n",
       "      <td>82</td>\n",
       "      <td>87.2</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1104</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>167</td>\n",
       "      <td>81</td>\n",
       "      <td>80.4</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     School Class Gender   Address  Height  Weight  Math Physics\n",
       "ID                                                              \n",
       "1103    S_1   C_1      M  street_2     186      82  87.2      B+\n",
       "1104    S_1   C_1      F  street_2     167      81  80.4      B-"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[[1103,1104]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>School</th>\n",
       "      <th>Class</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Address</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1104</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>167</td>\n",
       "      <td>81</td>\n",
       "      <td>80.4</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1105</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_4</td>\n",
       "      <td>159</td>\n",
       "      <td>64</td>\n",
       "      <td>84.8</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1201</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_5</td>\n",
       "      <td>188</td>\n",
       "      <td>68</td>\n",
       "      <td>97.0</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1202</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_4</td>\n",
       "      <td>176</td>\n",
       "      <td>94</td>\n",
       "      <td>63.5</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1203</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_6</td>\n",
       "      <td>160</td>\n",
       "      <td>53</td>\n",
       "      <td>58.8</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1204</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_5</td>\n",
       "      <td>162</td>\n",
       "      <td>63</td>\n",
       "      <td>33.8</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1205</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>167</td>\n",
       "      <td>63</td>\n",
       "      <td>68.4</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1301</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>161</td>\n",
       "      <td>68</td>\n",
       "      <td>31.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1302</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_1</td>\n",
       "      <td>175</td>\n",
       "      <td>57</td>\n",
       "      <td>87.7</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1303</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>188</td>\n",
       "      <td>82</td>\n",
       "      <td>49.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1304</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_2</td>\n",
       "      <td>195</td>\n",
       "      <td>70</td>\n",
       "      <td>85.2</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1305</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_5</td>\n",
       "      <td>187</td>\n",
       "      <td>69</td>\n",
       "      <td>61.7</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2101</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>174</td>\n",
       "      <td>84</td>\n",
       "      <td>83.3</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2102</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>161</td>\n",
       "      <td>61</td>\n",
       "      <td>50.6</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2103</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>157</td>\n",
       "      <td>61</td>\n",
       "      <td>52.5</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2104</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_5</td>\n",
       "      <td>159</td>\n",
       "      <td>97</td>\n",
       "      <td>72.2</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2105</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>170</td>\n",
       "      <td>81</td>\n",
       "      <td>34.2</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2201</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_5</td>\n",
       "      <td>193</td>\n",
       "      <td>100</td>\n",
       "      <td>39.1</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2202</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_7</td>\n",
       "      <td>194</td>\n",
       "      <td>77</td>\n",
       "      <td>68.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2203</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>155</td>\n",
       "      <td>91</td>\n",
       "      <td>73.8</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2204</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_1</td>\n",
       "      <td>175</td>\n",
       "      <td>74</td>\n",
       "      <td>47.2</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2205</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_7</td>\n",
       "      <td>183</td>\n",
       "      <td>76</td>\n",
       "      <td>85.4</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2301</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_4</td>\n",
       "      <td>157</td>\n",
       "      <td>78</td>\n",
       "      <td>72.3</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2302</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_5</td>\n",
       "      <td>171</td>\n",
       "      <td>88</td>\n",
       "      <td>32.7</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2303</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_7</td>\n",
       "      <td>190</td>\n",
       "      <td>99</td>\n",
       "      <td>65.9</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2304</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>164</td>\n",
       "      <td>81</td>\n",
       "      <td>95.5</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2305</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>187</td>\n",
       "      <td>73</td>\n",
       "      <td>48.9</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2401</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>192</td>\n",
       "      <td>62</td>\n",
       "      <td>45.3</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2402</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>166</td>\n",
       "      <td>82</td>\n",
       "      <td>48.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2403</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>158</td>\n",
       "      <td>60</td>\n",
       "      <td>59.7</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2404</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>160</td>\n",
       "      <td>84</td>\n",
       "      <td>67.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2405</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>193</td>\n",
       "      <td>54</td>\n",
       "      <td>47.6</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     School Class Gender   Address  Height  Weight  Math Physics\n",
       "ID                                                              \n",
       "1104    S_1   C_1      F  street_2     167      81  80.4      B-\n",
       "1105    S_1   C_1      F  street_4     159      64  84.8      B+\n",
       "1201    S_1   C_2      M  street_5     188      68  97.0      A-\n",
       "1202    S_1   C_2      F  street_4     176      94  63.5      B-\n",
       "1203    S_1   C_2      M  street_6     160      53  58.8      A+\n",
       "1204    S_1   C_2      F  street_5     162      63  33.8       B\n",
       "1205    S_1   C_2      F  street_6     167      63  68.4      B-\n",
       "1301    S_1   C_3      M  street_4     161      68  31.5      B+\n",
       "1302    S_1   C_3      F  street_1     175      57  87.7      A-\n",
       "1303    S_1   C_3      M  street_7     188      82  49.7       B\n",
       "1304    S_1   C_3      M  street_2     195      70  85.2       A\n",
       "1305    S_1   C_3      F  street_5     187      69  61.7      B-\n",
       "2101    S_2   C_1      M  street_7     174      84  83.3       C\n",
       "2102    S_2   C_1      F  street_6     161      61  50.6      B+\n",
       "2103    S_2   C_1      M  street_4     157      61  52.5      B-\n",
       "2104    S_2   C_1      F  street_5     159      97  72.2      B+\n",
       "2105    S_2   C_1      M  street_4     170      81  34.2       A\n",
       "2201    S_2   C_2      M  street_5     193     100  39.1       B\n",
       "2202    S_2   C_2      F  street_7     194      77  68.5      B+\n",
       "2203    S_2   C_2      M  street_4     155      91  73.8      A+\n",
       "2204    S_2   C_2      M  street_1     175      74  47.2      B-\n",
       "2205    S_2   C_2      F  street_7     183      76  85.4       B\n",
       "2301    S_2   C_3      F  street_4     157      78  72.3      B+\n",
       "2302    S_2   C_3      M  street_5     171      88  32.7       A\n",
       "2303    S_2   C_3      F  street_7     190      99  65.9       C\n",
       "2304    S_2   C_3      F  street_6     164      81  95.5      A-\n",
       "2305    S_2   C_3      M  street_4     187      73  48.9       B\n",
       "2401    S_2   C_4      F  street_2     192      62  45.3       A\n",
       "2402    S_2   C_4      M  street_7     166      82  48.7       B\n",
       "2403    S_2   C_4      F  street_6     158      60  59.7      B+\n",
       "2404    S_2   C_4      F  street_2     160      84  67.7       B\n",
       "2405    S_2   C_4      F  street_6     193      54  47.6       B"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[1104:]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "列索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Math</th>\n",
       "      <th>Height</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1101</th>\n",
       "      <td>34.0</td>\n",
       "      <td>173</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1102</th>\n",
       "      <td>32.5</td>\n",
       "      <td>192</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1103</th>\n",
       "      <td>87.2</td>\n",
       "      <td>186</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1104</th>\n",
       "      <td>80.4</td>\n",
       "      <td>167</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1105</th>\n",
       "      <td>84.8</td>\n",
       "      <td>159</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1201</th>\n",
       "      <td>97.0</td>\n",
       "      <td>188</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1202</th>\n",
       "      <td>63.5</td>\n",
       "      <td>176</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1203</th>\n",
       "      <td>58.8</td>\n",
       "      <td>160</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1204</th>\n",
       "      <td>33.8</td>\n",
       "      <td>162</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1205</th>\n",
       "      <td>68.4</td>\n",
       "      <td>167</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1301</th>\n",
       "      <td>31.5</td>\n",
       "      <td>161</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1302</th>\n",
       "      <td>87.7</td>\n",
       "      <td>175</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1303</th>\n",
       "      <td>49.7</td>\n",
       "      <td>188</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1304</th>\n",
       "      <td>85.2</td>\n",
       "      <td>195</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1305</th>\n",
       "      <td>61.7</td>\n",
       "      <td>187</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2101</th>\n",
       "      <td>83.3</td>\n",
       "      <td>174</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2102</th>\n",
       "      <td>50.6</td>\n",
       "      <td>161</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2103</th>\n",
       "      <td>52.5</td>\n",
       "      <td>157</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2104</th>\n",
       "      <td>72.2</td>\n",
       "      <td>159</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2105</th>\n",
       "      <td>34.2</td>\n",
       "      <td>170</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2201</th>\n",
       "      <td>39.1</td>\n",
       "      <td>193</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2202</th>\n",
       "      <td>68.5</td>\n",
       "      <td>194</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2203</th>\n",
       "      <td>73.8</td>\n",
       "      <td>155</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2204</th>\n",
       "      <td>47.2</td>\n",
       "      <td>175</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2205</th>\n",
       "      <td>85.4</td>\n",
       "      <td>183</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2301</th>\n",
       "      <td>72.3</td>\n",
       "      <td>157</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2302</th>\n",
       "      <td>32.7</td>\n",
       "      <td>171</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2303</th>\n",
       "      <td>65.9</td>\n",
       "      <td>190</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2304</th>\n",
       "      <td>95.5</td>\n",
       "      <td>164</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2305</th>\n",
       "      <td>48.9</td>\n",
       "      <td>187</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2401</th>\n",
       "      <td>45.3</td>\n",
       "      <td>192</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2402</th>\n",
       "      <td>48.7</td>\n",
       "      <td>166</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2403</th>\n",
       "      <td>59.7</td>\n",
       "      <td>158</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2404</th>\n",
       "      <td>67.7</td>\n",
       "      <td>160</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2405</th>\n",
       "      <td>47.6</td>\n",
       "      <td>193</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Math  Height\n",
       "ID                \n",
       "1101  34.0     173\n",
       "1102  32.5     192\n",
       "1103  87.2     186\n",
       "1104  80.4     167\n",
       "1105  84.8     159\n",
       "1201  97.0     188\n",
       "1202  63.5     176\n",
       "1203  58.8     160\n",
       "1204  33.8     162\n",
       "1205  68.4     167\n",
       "1301  31.5     161\n",
       "1302  87.7     175\n",
       "1303  49.7     188\n",
       "1304  85.2     195\n",
       "1305  61.7     187\n",
       "2101  83.3     174\n",
       "2102  50.6     161\n",
       "2103  52.5     157\n",
       "2104  72.2     159\n",
       "2105  34.2     170\n",
       "2201  39.1     193\n",
       "2202  68.5     194\n",
       "2203  73.8     155\n",
       "2204  47.2     175\n",
       "2205  85.4     183\n",
       "2301  72.3     157\n",
       "2302  32.7     171\n",
       "2303  65.9     190\n",
       "2304  95.5     164\n",
       "2305  48.9     187\n",
       "2401  45.3     192\n",
       "2402  48.7     166\n",
       "2403  59.7     158\n",
       "2404  67.7     160\n",
       "2405  47.6     193"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[:,['Math','Height']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1101</th>\n",
       "      <td>173</td>\n",
       "      <td>63</td>\n",
       "      <td>34.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1102</th>\n",
       "      <td>192</td>\n",
       "      <td>73</td>\n",
       "      <td>32.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1103</th>\n",
       "      <td>186</td>\n",
       "      <td>82</td>\n",
       "      <td>87.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1104</th>\n",
       "      <td>167</td>\n",
       "      <td>81</td>\n",
       "      <td>80.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1105</th>\n",
       "      <td>159</td>\n",
       "      <td>64</td>\n",
       "      <td>84.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1201</th>\n",
       "      <td>188</td>\n",
       "      <td>68</td>\n",
       "      <td>97.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1202</th>\n",
       "      <td>176</td>\n",
       "      <td>94</td>\n",
       "      <td>63.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1203</th>\n",
       "      <td>160</td>\n",
       "      <td>53</td>\n",
       "      <td>58.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1204</th>\n",
       "      <td>162</td>\n",
       "      <td>63</td>\n",
       "      <td>33.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1205</th>\n",
       "      <td>167</td>\n",
       "      <td>63</td>\n",
       "      <td>68.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1301</th>\n",
       "      <td>161</td>\n",
       "      <td>68</td>\n",
       "      <td>31.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1302</th>\n",
       "      <td>175</td>\n",
       "      <td>57</td>\n",
       "      <td>87.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1303</th>\n",
       "      <td>188</td>\n",
       "      <td>82</td>\n",
       "      <td>49.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1304</th>\n",
       "      <td>195</td>\n",
       "      <td>70</td>\n",
       "      <td>85.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1305</th>\n",
       "      <td>187</td>\n",
       "      <td>69</td>\n",
       "      <td>61.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2101</th>\n",
       "      <td>174</td>\n",
       "      <td>84</td>\n",
       "      <td>83.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2102</th>\n",
       "      <td>161</td>\n",
       "      <td>61</td>\n",
       "      <td>50.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2103</th>\n",
       "      <td>157</td>\n",
       "      <td>61</td>\n",
       "      <td>52.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2104</th>\n",
       "      <td>159</td>\n",
       "      <td>97</td>\n",
       "      <td>72.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2105</th>\n",
       "      <td>170</td>\n",
       "      <td>81</td>\n",
       "      <td>34.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2201</th>\n",
       "      <td>193</td>\n",
       "      <td>100</td>\n",
       "      <td>39.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2202</th>\n",
       "      <td>194</td>\n",
       "      <td>77</td>\n",
       "      <td>68.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2203</th>\n",
       "      <td>155</td>\n",
       "      <td>91</td>\n",
       "      <td>73.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2204</th>\n",
       "      <td>175</td>\n",
       "      <td>74</td>\n",
       "      <td>47.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2205</th>\n",
       "      <td>183</td>\n",
       "      <td>76</td>\n",
       "      <td>85.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2301</th>\n",
       "      <td>157</td>\n",
       "      <td>78</td>\n",
       "      <td>72.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2302</th>\n",
       "      <td>171</td>\n",
       "      <td>88</td>\n",
       "      <td>32.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2303</th>\n",
       "      <td>190</td>\n",
       "      <td>99</td>\n",
       "      <td>65.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2304</th>\n",
       "      <td>164</td>\n",
       "      <td>81</td>\n",
       "      <td>95.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2305</th>\n",
       "      <td>187</td>\n",
       "      <td>73</td>\n",
       "      <td>48.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2401</th>\n",
       "      <td>192</td>\n",
       "      <td>62</td>\n",
       "      <td>45.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2402</th>\n",
       "      <td>166</td>\n",
       "      <td>82</td>\n",
       "      <td>48.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2403</th>\n",
       "      <td>158</td>\n",
       "      <td>60</td>\n",
       "      <td>59.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2404</th>\n",
       "      <td>160</td>\n",
       "      <td>84</td>\n",
       "      <td>67.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2405</th>\n",
       "      <td>193</td>\n",
       "      <td>54</td>\n",
       "      <td>47.6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Height  Weight  Math\n",
       "ID                        \n",
       "1101     173      63  34.0\n",
       "1102     192      73  32.5\n",
       "1103     186      82  87.2\n",
       "1104     167      81  80.4\n",
       "1105     159      64  84.8\n",
       "1201     188      68  97.0\n",
       "1202     176      94  63.5\n",
       "1203     160      53  58.8\n",
       "1204     162      63  33.8\n",
       "1205     167      63  68.4\n",
       "1301     161      68  31.5\n",
       "1302     175      57  87.7\n",
       "1303     188      82  49.7\n",
       "1304     195      70  85.2\n",
       "1305     187      69  61.7\n",
       "2101     174      84  83.3\n",
       "2102     161      61  50.6\n",
       "2103     157      61  52.5\n",
       "2104     159      97  72.2\n",
       "2105     170      81  34.2\n",
       "2201     193     100  39.1\n",
       "2202     194      77  68.5\n",
       "2203     155      91  73.8\n",
       "2204     175      74  47.2\n",
       "2205     183      76  85.4\n",
       "2301     157      78  72.3\n",
       "2302     171      88  32.7\n",
       "2303     190      99  65.9\n",
       "2304     164      81  95.5\n",
       "2305     187      73  48.9\n",
       "2401     192      62  45.3\n",
       "2402     166      82  48.7\n",
       "2403     158      60  59.7\n",
       "2404     160      84  67.7\n",
       "2405     193      54  47.6"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[:,'Height':'Math']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1102</th>\n",
       "      <td>192</td>\n",
       "      <td>73</td>\n",
       "      <td>32.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1105</th>\n",
       "      <td>159</td>\n",
       "      <td>64</td>\n",
       "      <td>84.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1203</th>\n",
       "      <td>160</td>\n",
       "      <td>53</td>\n",
       "      <td>58.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1301</th>\n",
       "      <td>161</td>\n",
       "      <td>68</td>\n",
       "      <td>31.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1304</th>\n",
       "      <td>195</td>\n",
       "      <td>70</td>\n",
       "      <td>85.2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Height  Weight  Math\n",
       "ID                        \n",
       "1102     192      73  32.5\n",
       "1105     159      64  84.8\n",
       "1203     160      53  58.8\n",
       "1301     161      68  31.5\n",
       "1304     195      70  85.2"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[1102:2401:3,'Height':'Math'].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>School</th>\n",
       "      <th>Class</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Address</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1101</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_1</td>\n",
       "      <td>173</td>\n",
       "      <td>63</td>\n",
       "      <td>34.0</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1103</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_2</td>\n",
       "      <td>186</td>\n",
       "      <td>82</td>\n",
       "      <td>87.2</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1201</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_5</td>\n",
       "      <td>188</td>\n",
       "      <td>68</td>\n",
       "      <td>97.0</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1203</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_6</td>\n",
       "      <td>160</td>\n",
       "      <td>53</td>\n",
       "      <td>58.8</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1301</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>161</td>\n",
       "      <td>68</td>\n",
       "      <td>31.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1303</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>188</td>\n",
       "      <td>82</td>\n",
       "      <td>49.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1304</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_2</td>\n",
       "      <td>195</td>\n",
       "      <td>70</td>\n",
       "      <td>85.2</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2101</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>174</td>\n",
       "      <td>84</td>\n",
       "      <td>83.3</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2103</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>157</td>\n",
       "      <td>61</td>\n",
       "      <td>52.5</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2105</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>170</td>\n",
       "      <td>81</td>\n",
       "      <td>34.2</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2201</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_5</td>\n",
       "      <td>193</td>\n",
       "      <td>100</td>\n",
       "      <td>39.1</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2203</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>155</td>\n",
       "      <td>91</td>\n",
       "      <td>73.8</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2204</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_1</td>\n",
       "      <td>175</td>\n",
       "      <td>74</td>\n",
       "      <td>47.2</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2302</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_5</td>\n",
       "      <td>171</td>\n",
       "      <td>88</td>\n",
       "      <td>32.7</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2305</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>187</td>\n",
       "      <td>73</td>\n",
       "      <td>48.9</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2402</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>166</td>\n",
       "      <td>82</td>\n",
       "      <td>48.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     School Class Gender   Address  Height  Weight  Math Physics\n",
       "ID                                                              \n",
       "1101    S_1   C_1      M  street_1     173      63  34.0      A+\n",
       "1103    S_1   C_1      M  street_2     186      82  87.2      B+\n",
       "1201    S_1   C_2      M  street_5     188      68  97.0      A-\n",
       "1203    S_1   C_2      M  street_6     160      53  58.8      A+\n",
       "1301    S_1   C_3      M  street_4     161      68  31.5      B+\n",
       "1303    S_1   C_3      M  street_7     188      82  49.7       B\n",
       "1304    S_1   C_3      M  street_2     195      70  85.2       A\n",
       "2101    S_2   C_1      M  street_7     174      84  83.3       C\n",
       "2103    S_2   C_1      M  street_4     157      61  52.5      B-\n",
       "2105    S_2   C_1      M  street_4     170      81  34.2       A\n",
       "2201    S_2   C_2      M  street_5     193     100  39.1       B\n",
       "2203    S_2   C_2      M  street_4     155      91  73.8      A+\n",
       "2204    S_2   C_2      M  street_1     175      74  47.2      B-\n",
       "2302    S_2   C_3      M  street_5     171      88  32.7       A\n",
       "2305    S_2   C_3      M  street_4     187      73  48.9       B\n",
       "2402    S_2   C_4      M  street_7     166      82  48.7       B"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#函数式索引 可以用于筛选\n",
    "df.loc[lambda x:x['Gender']=='M']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>School</th>\n",
       "      <th>Class</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Address</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1105</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_4</td>\n",
       "      <td>159</td>\n",
       "      <td>64</td>\n",
       "      <td>84.8</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1202</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_4</td>\n",
       "      <td>176</td>\n",
       "      <td>94</td>\n",
       "      <td>63.5</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1301</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>161</td>\n",
       "      <td>68</td>\n",
       "      <td>31.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1303</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>188</td>\n",
       "      <td>82</td>\n",
       "      <td>49.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2101</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>174</td>\n",
       "      <td>84</td>\n",
       "      <td>83.3</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2103</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>157</td>\n",
       "      <td>61</td>\n",
       "      <td>52.5</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2105</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>170</td>\n",
       "      <td>81</td>\n",
       "      <td>34.2</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2202</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_7</td>\n",
       "      <td>194</td>\n",
       "      <td>77</td>\n",
       "      <td>68.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2203</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>155</td>\n",
       "      <td>91</td>\n",
       "      <td>73.8</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2205</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_7</td>\n",
       "      <td>183</td>\n",
       "      <td>76</td>\n",
       "      <td>85.4</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2301</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_4</td>\n",
       "      <td>157</td>\n",
       "      <td>78</td>\n",
       "      <td>72.3</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2303</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_7</td>\n",
       "      <td>190</td>\n",
       "      <td>99</td>\n",
       "      <td>65.9</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2305</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>187</td>\n",
       "      <td>73</td>\n",
       "      <td>48.9</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2402</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>166</td>\n",
       "      <td>82</td>\n",
       "      <td>48.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     School Class Gender   Address  Height  Weight  Math Physics\n",
       "ID                                                              \n",
       "1105    S_1   C_1      F  street_4     159      64  84.8      B+\n",
       "1202    S_1   C_2      F  street_4     176      94  63.5      B-\n",
       "1301    S_1   C_3      M  street_4     161      68  31.5      B+\n",
       "1303    S_1   C_3      M  street_7     188      82  49.7       B\n",
       "2101    S_2   C_1      M  street_7     174      84  83.3       C\n",
       "2103    S_2   C_1      M  street_4     157      61  52.5      B-\n",
       "2105    S_2   C_1      M  street_4     170      81  34.2       A\n",
       "2202    S_2   C_2      F  street_7     194      77  68.5      B+\n",
       "2203    S_2   C_2      M  street_4     155      91  73.8      A+\n",
       "2205    S_2   C_2      F  street_7     183      76  85.4       B\n",
       "2301    S_2   C_3      F  street_4     157      78  72.3      B+\n",
       "2303    S_2   C_3      F  street_7     190      99  65.9       C\n",
       "2305    S_2   C_3      M  street_4     187      73  48.9       B\n",
       "2402    S_2   C_4      M  street_7     166      82  48.7       B"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[df['Address'].isin(['street_7','street_4'])]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>School</th>\n",
       "      <th>Class</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Address</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1105</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_4</td>\n",
       "      <td>159</td>\n",
       "      <td>64</td>\n",
       "      <td>84.8</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1202</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_4</td>\n",
       "      <td>176</td>\n",
       "      <td>94</td>\n",
       "      <td>63.5</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1301</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>161</td>\n",
       "      <td>68</td>\n",
       "      <td>31.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1303</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>188</td>\n",
       "      <td>82</td>\n",
       "      <td>49.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2101</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>174</td>\n",
       "      <td>84</td>\n",
       "      <td>83.3</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2103</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>157</td>\n",
       "      <td>61</td>\n",
       "      <td>52.5</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2105</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>170</td>\n",
       "      <td>81</td>\n",
       "      <td>34.2</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2202</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_7</td>\n",
       "      <td>194</td>\n",
       "      <td>77</td>\n",
       "      <td>68.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2203</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>155</td>\n",
       "      <td>91</td>\n",
       "      <td>73.8</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2205</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_7</td>\n",
       "      <td>183</td>\n",
       "      <td>76</td>\n",
       "      <td>85.4</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2301</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_4</td>\n",
       "      <td>157</td>\n",
       "      <td>78</td>\n",
       "      <td>72.3</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2303</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_7</td>\n",
       "      <td>190</td>\n",
       "      <td>99</td>\n",
       "      <td>65.9</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2305</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>187</td>\n",
       "      <td>73</td>\n",
       "      <td>48.9</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2402</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>166</td>\n",
       "      <td>82</td>\n",
       "      <td>48.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     School Class Gender   Address  Height  Weight  Math Physics\n",
       "ID                                                              \n",
       "1105    S_1   C_1      F  street_4     159      64  84.8      B+\n",
       "1202    S_1   C_2      F  street_4     176      94  63.5      B-\n",
       "1301    S_1   C_3      M  street_4     161      68  31.5      B+\n",
       "1303    S_1   C_3      M  street_7     188      82  49.7       B\n",
       "2101    S_2   C_1      M  street_7     174      84  83.3       C\n",
       "2103    S_2   C_1      M  street_4     157      61  52.5      B-\n",
       "2105    S_2   C_1      M  street_4     170      81  34.2       A\n",
       "2202    S_2   C_2      F  street_7     194      77  68.5      B+\n",
       "2203    S_2   C_2      M  street_4     155      91  73.8      A+\n",
       "2205    S_2   C_2      F  street_7     183      76  85.4       B\n",
       "2301    S_2   C_3      F  street_4     157      78  72.3      B+\n",
       "2303    S_2   C_3      F  street_7     190      99  65.9       C\n",
       "2305    S_2   C_3      M  street_4     187      73  48.9       B\n",
       "2402    S_2   C_4      M  street_7     166      82  48.7       B"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[[True if i[-1]=='4' or i[-1]=='7' else False for i in df['Address'].values]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>School</th>\n",
       "      <th>Class</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Address</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1101</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_1</td>\n",
       "      <td>173</td>\n",
       "      <td>63</td>\n",
       "      <td>34.0</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1102</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>192</td>\n",
       "      <td>73</td>\n",
       "      <td>32.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1103</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_2</td>\n",
       "      <td>186</td>\n",
       "      <td>82</td>\n",
       "      <td>87.2</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1104</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>167</td>\n",
       "      <td>81</td>\n",
       "      <td>80.4</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1105</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_4</td>\n",
       "      <td>159</td>\n",
       "      <td>64</td>\n",
       "      <td>84.8</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1201</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_5</td>\n",
       "      <td>188</td>\n",
       "      <td>68</td>\n",
       "      <td>97.0</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1202</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_4</td>\n",
       "      <td>176</td>\n",
       "      <td>94</td>\n",
       "      <td>63.5</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1203</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_6</td>\n",
       "      <td>160</td>\n",
       "      <td>53</td>\n",
       "      <td>58.8</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1204</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_5</td>\n",
       "      <td>162</td>\n",
       "      <td>63</td>\n",
       "      <td>33.8</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1205</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>167</td>\n",
       "      <td>63</td>\n",
       "      <td>68.4</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1301</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>161</td>\n",
       "      <td>68</td>\n",
       "      <td>31.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1302</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_1</td>\n",
       "      <td>175</td>\n",
       "      <td>57</td>\n",
       "      <td>87.7</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1303</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>188</td>\n",
       "      <td>82</td>\n",
       "      <td>49.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1304</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_2</td>\n",
       "      <td>195</td>\n",
       "      <td>70</td>\n",
       "      <td>85.2</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1305</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_5</td>\n",
       "      <td>187</td>\n",
       "      <td>69</td>\n",
       "      <td>61.7</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2101</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>174</td>\n",
       "      <td>84</td>\n",
       "      <td>83.3</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2102</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>161</td>\n",
       "      <td>61</td>\n",
       "      <td>50.6</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2103</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>157</td>\n",
       "      <td>61</td>\n",
       "      <td>52.5</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2104</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_5</td>\n",
       "      <td>159</td>\n",
       "      <td>97</td>\n",
       "      <td>72.2</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2105</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>170</td>\n",
       "      <td>81</td>\n",
       "      <td>34.2</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2201</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_5</td>\n",
       "      <td>193</td>\n",
       "      <td>100</td>\n",
       "      <td>39.1</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2202</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_7</td>\n",
       "      <td>194</td>\n",
       "      <td>77</td>\n",
       "      <td>68.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2203</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>155</td>\n",
       "      <td>91</td>\n",
       "      <td>73.8</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2204</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_1</td>\n",
       "      <td>175</td>\n",
       "      <td>74</td>\n",
       "      <td>47.2</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2205</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_7</td>\n",
       "      <td>183</td>\n",
       "      <td>76</td>\n",
       "      <td>85.4</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2301</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_4</td>\n",
       "      <td>157</td>\n",
       "      <td>78</td>\n",
       "      <td>72.3</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2302</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_5</td>\n",
       "      <td>171</td>\n",
       "      <td>88</td>\n",
       "      <td>32.7</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2303</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_7</td>\n",
       "      <td>190</td>\n",
       "      <td>99</td>\n",
       "      <td>65.9</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2304</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>164</td>\n",
       "      <td>81</td>\n",
       "      <td>95.5</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2305</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>187</td>\n",
       "      <td>73</td>\n",
       "      <td>48.9</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2401</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>192</td>\n",
       "      <td>62</td>\n",
       "      <td>45.3</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2402</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>166</td>\n",
       "      <td>82</td>\n",
       "      <td>48.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2403</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>158</td>\n",
       "      <td>60</td>\n",
       "      <td>59.7</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2404</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>160</td>\n",
       "      <td>84</td>\n",
       "      <td>67.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2405</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>193</td>\n",
       "      <td>54</td>\n",
       "      <td>47.6</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     School Class Gender   Address  Height  Weight  Math Physics\n",
       "ID                                                              \n",
       "1101    S_1   C_1      M  street_1     173      63  34.0      A+\n",
       "1102    S_1   C_1      F  street_2     192      73  32.5      B+\n",
       "1103    S_1   C_1      M  street_2     186      82  87.2      B+\n",
       "1104    S_1   C_1      F  street_2     167      81  80.4      B-\n",
       "1105    S_1   C_1      F  street_4     159      64  84.8      B+\n",
       "1201    S_1   C_2      M  street_5     188      68  97.0      A-\n",
       "1202    S_1   C_2      F  street_4     176      94  63.5      B-\n",
       "1203    S_1   C_2      M  street_6     160      53  58.8      A+\n",
       "1204    S_1   C_2      F  street_5     162      63  33.8       B\n",
       "1205    S_1   C_2      F  street_6     167      63  68.4      B-\n",
       "1301    S_1   C_3      M  street_4     161      68  31.5      B+\n",
       "1302    S_1   C_3      F  street_1     175      57  87.7      A-\n",
       "1303    S_1   C_3      M  street_7     188      82  49.7       B\n",
       "1304    S_1   C_3      M  street_2     195      70  85.2       A\n",
       "1305    S_1   C_3      F  street_5     187      69  61.7      B-\n",
       "2101    S_2   C_1      M  street_7     174      84  83.3       C\n",
       "2102    S_2   C_1      F  street_6     161      61  50.6      B+\n",
       "2103    S_2   C_1      M  street_4     157      61  52.5      B-\n",
       "2104    S_2   C_1      F  street_5     159      97  72.2      B+\n",
       "2105    S_2   C_1      M  street_4     170      81  34.2       A\n",
       "2201    S_2   C_2      M  street_5     193     100  39.1       B\n",
       "2202    S_2   C_2      F  street_7     194      77  68.5      B+\n",
       "2203    S_2   C_2      M  street_4     155      91  73.8      A+\n",
       "2204    S_2   C_2      M  street_1     175      74  47.2      B-\n",
       "2205    S_2   C_2      F  street_7     183      76  85.4       B\n",
       "2301    S_2   C_3      F  street_4     157      78  72.3      B+\n",
       "2302    S_2   C_3      M  street_5     171      88  32.7       A\n",
       "2303    S_2   C_3      F  street_7     190      99  65.9       C\n",
       "2304    S_2   C_3      F  street_6     164      81  95.5      A-\n",
       "2305    S_2   C_3      M  street_4     187      73  48.9       B\n",
       "2401    S_2   C_4      F  street_2     192      62  45.3       A\n",
       "2402    S_2   C_4      M  street_7     166      82  48.7       B\n",
       "2403    S_2   C_4      F  street_6     158      60  59.7      B+\n",
       "2404    S_2   C_4      F  street_2     160      84  67.7       B\n",
       "2405    S_2   C_4      F  street_6     193      54  47.6       B"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "iloc索引不包括最右边的  iloc中接收的参数只能为整数或整数列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Physics</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Address</th>\n",
       "      <th>Class</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1101</th>\n",
       "      <td>A+</td>\n",
       "      <td>63</td>\n",
       "      <td>street_1</td>\n",
       "      <td>C_1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1102</th>\n",
       "      <td>B+</td>\n",
       "      <td>73</td>\n",
       "      <td>street_2</td>\n",
       "      <td>C_1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1103</th>\n",
       "      <td>B+</td>\n",
       "      <td>82</td>\n",
       "      <td>street_2</td>\n",
       "      <td>C_1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1104</th>\n",
       "      <td>B-</td>\n",
       "      <td>81</td>\n",
       "      <td>street_2</td>\n",
       "      <td>C_1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1105</th>\n",
       "      <td>B+</td>\n",
       "      <td>64</td>\n",
       "      <td>street_4</td>\n",
       "      <td>C_1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1201</th>\n",
       "      <td>A-</td>\n",
       "      <td>68</td>\n",
       "      <td>street_5</td>\n",
       "      <td>C_2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1202</th>\n",
       "      <td>B-</td>\n",
       "      <td>94</td>\n",
       "      <td>street_4</td>\n",
       "      <td>C_2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1203</th>\n",
       "      <td>A+</td>\n",
       "      <td>53</td>\n",
       "      <td>street_6</td>\n",
       "      <td>C_2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1204</th>\n",
       "      <td>B</td>\n",
       "      <td>63</td>\n",
       "      <td>street_5</td>\n",
       "      <td>C_2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1205</th>\n",
       "      <td>B-</td>\n",
       "      <td>63</td>\n",
       "      <td>street_6</td>\n",
       "      <td>C_2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1301</th>\n",
       "      <td>B+</td>\n",
       "      <td>68</td>\n",
       "      <td>street_4</td>\n",
       "      <td>C_3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1302</th>\n",
       "      <td>A-</td>\n",
       "      <td>57</td>\n",
       "      <td>street_1</td>\n",
       "      <td>C_3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1303</th>\n",
       "      <td>B</td>\n",
       "      <td>82</td>\n",
       "      <td>street_7</td>\n",
       "      <td>C_3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1304</th>\n",
       "      <td>A</td>\n",
       "      <td>70</td>\n",
       "      <td>street_2</td>\n",
       "      <td>C_3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1305</th>\n",
       "      <td>B-</td>\n",
       "      <td>69</td>\n",
       "      <td>street_5</td>\n",
       "      <td>C_3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2101</th>\n",
       "      <td>C</td>\n",
       "      <td>84</td>\n",
       "      <td>street_7</td>\n",
       "      <td>C_1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2102</th>\n",
       "      <td>B+</td>\n",
       "      <td>61</td>\n",
       "      <td>street_6</td>\n",
       "      <td>C_1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2103</th>\n",
       "      <td>B-</td>\n",
       "      <td>61</td>\n",
       "      <td>street_4</td>\n",
       "      <td>C_1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2104</th>\n",
       "      <td>B+</td>\n",
       "      <td>97</td>\n",
       "      <td>street_5</td>\n",
       "      <td>C_1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2105</th>\n",
       "      <td>A</td>\n",
       "      <td>81</td>\n",
       "      <td>street_4</td>\n",
       "      <td>C_1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2201</th>\n",
       "      <td>B</td>\n",
       "      <td>100</td>\n",
       "      <td>street_5</td>\n",
       "      <td>C_2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2202</th>\n",
       "      <td>B+</td>\n",
       "      <td>77</td>\n",
       "      <td>street_7</td>\n",
       "      <td>C_2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2203</th>\n",
       "      <td>A+</td>\n",
       "      <td>91</td>\n",
       "      <td>street_4</td>\n",
       "      <td>C_2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2204</th>\n",
       "      <td>B-</td>\n",
       "      <td>74</td>\n",
       "      <td>street_1</td>\n",
       "      <td>C_2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2205</th>\n",
       "      <td>B</td>\n",
       "      <td>76</td>\n",
       "      <td>street_7</td>\n",
       "      <td>C_2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2301</th>\n",
       "      <td>B+</td>\n",
       "      <td>78</td>\n",
       "      <td>street_4</td>\n",
       "      <td>C_3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2302</th>\n",
       "      <td>A</td>\n",
       "      <td>88</td>\n",
       "      <td>street_5</td>\n",
       "      <td>C_3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2303</th>\n",
       "      <td>C</td>\n",
       "      <td>99</td>\n",
       "      <td>street_7</td>\n",
       "      <td>C_3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2304</th>\n",
       "      <td>A-</td>\n",
       "      <td>81</td>\n",
       "      <td>street_6</td>\n",
       "      <td>C_3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2305</th>\n",
       "      <td>B</td>\n",
       "      <td>73</td>\n",
       "      <td>street_4</td>\n",
       "      <td>C_3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2401</th>\n",
       "      <td>A</td>\n",
       "      <td>62</td>\n",
       "      <td>street_2</td>\n",
       "      <td>C_4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2402</th>\n",
       "      <td>B</td>\n",
       "      <td>82</td>\n",
       "      <td>street_7</td>\n",
       "      <td>C_4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2403</th>\n",
       "      <td>B+</td>\n",
       "      <td>60</td>\n",
       "      <td>street_6</td>\n",
       "      <td>C_4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2404</th>\n",
       "      <td>B</td>\n",
       "      <td>84</td>\n",
       "      <td>street_2</td>\n",
       "      <td>C_4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2405</th>\n",
       "      <td>B</td>\n",
       "      <td>54</td>\n",
       "      <td>street_6</td>\n",
       "      <td>C_4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     Physics  Weight   Address Class\n",
       "ID                                  \n",
       "1101      A+      63  street_1   C_1\n",
       "1102      B+      73  street_2   C_1\n",
       "1103      B+      82  street_2   C_1\n",
       "1104      B-      81  street_2   C_1\n",
       "1105      B+      64  street_4   C_1\n",
       "1201      A-      68  street_5   C_2\n",
       "1202      B-      94  street_4   C_2\n",
       "1203      A+      53  street_6   C_2\n",
       "1204       B      63  street_5   C_2\n",
       "1205      B-      63  street_6   C_2\n",
       "1301      B+      68  street_4   C_3\n",
       "1302      A-      57  street_1   C_3\n",
       "1303       B      82  street_7   C_3\n",
       "1304       A      70  street_2   C_3\n",
       "1305      B-      69  street_5   C_3\n",
       "2101       C      84  street_7   C_1\n",
       "2102      B+      61  street_6   C_1\n",
       "2103      B-      61  street_4   C_1\n",
       "2104      B+      97  street_5   C_1\n",
       "2105       A      81  street_4   C_1\n",
       "2201       B     100  street_5   C_2\n",
       "2202      B+      77  street_7   C_2\n",
       "2203      A+      91  street_4   C_2\n",
       "2204      B-      74  street_1   C_2\n",
       "2205       B      76  street_7   C_2\n",
       "2301      B+      78  street_4   C_3\n",
       "2302       A      88  street_5   C_3\n",
       "2303       C      99  street_7   C_3\n",
       "2304      A-      81  street_6   C_3\n",
       "2305       B      73  street_4   C_3\n",
       "2401       A      62  street_2   C_4\n",
       "2402       B      82  street_7   C_4\n",
       "2403      B+      60  street_6   C_4\n",
       "2404       B      84  street_2   C_4\n",
       "2405       B      54  street_6   C_4"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[:,7::-2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "34.0"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = pd.Series(df['Math'],index=df.index)\n",
    "s[1101]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ID\n",
       "1101    34.0\n",
       "1102    32.5\n",
       "1103    87.2\n",
       "1104    80.4\n",
       "Name: Math, dtype: float64"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s[0:4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ID\n",
       "1103    87.2\n",
       "1104    80.4\n",
       "1105    84.8\n",
       "1201    97.0\n",
       "1302    87.7\n",
       "1304    85.2\n",
       "2101    83.3\n",
       "2205    85.4\n",
       "2304    95.5\n",
       "Name: Math, dtype: float64"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s[s>80]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "[]多列索引 []比较适合列选择或者是布尔选择 loc比较适合行选择"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1101</th>\n",
       "      <td>34.0</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1102</th>\n",
       "      <td>32.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1103</th>\n",
       "      <td>87.2</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1104</th>\n",
       "      <td>80.4</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1105</th>\n",
       "      <td>84.8</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1201</th>\n",
       "      <td>97.0</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1202</th>\n",
       "      <td>63.5</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1203</th>\n",
       "      <td>58.8</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1204</th>\n",
       "      <td>33.8</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1205</th>\n",
       "      <td>68.4</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1301</th>\n",
       "      <td>31.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1302</th>\n",
       "      <td>87.7</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1303</th>\n",
       "      <td>49.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1304</th>\n",
       "      <td>85.2</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1305</th>\n",
       "      <td>61.7</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2101</th>\n",
       "      <td>83.3</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2102</th>\n",
       "      <td>50.6</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2103</th>\n",
       "      <td>52.5</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2104</th>\n",
       "      <td>72.2</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2105</th>\n",
       "      <td>34.2</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2201</th>\n",
       "      <td>39.1</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2202</th>\n",
       "      <td>68.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2203</th>\n",
       "      <td>73.8</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2204</th>\n",
       "      <td>47.2</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2205</th>\n",
       "      <td>85.4</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2301</th>\n",
       "      <td>72.3</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2302</th>\n",
       "      <td>32.7</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2303</th>\n",
       "      <td>65.9</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2304</th>\n",
       "      <td>95.5</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2305</th>\n",
       "      <td>48.9</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2401</th>\n",
       "      <td>45.3</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2402</th>\n",
       "      <td>48.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2403</th>\n",
       "      <td>59.7</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2404</th>\n",
       "      <td>67.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2405</th>\n",
       "      <td>47.6</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Math Physics\n",
       "ID                \n",
       "1101  34.0      A+\n",
       "1102  32.5      B+\n",
       "1103  87.2      B+\n",
       "1104  80.4      B-\n",
       "1105  84.8      B+\n",
       "1201  97.0      A-\n",
       "1202  63.5      B-\n",
       "1203  58.8      A+\n",
       "1204  33.8       B\n",
       "1205  68.4      B-\n",
       "1301  31.5      B+\n",
       "1302  87.7      A-\n",
       "1303  49.7       B\n",
       "1304  85.2       A\n",
       "1305  61.7      B-\n",
       "2101  83.3       C\n",
       "2102  50.6      B+\n",
       "2103  52.5      B-\n",
       "2104  72.2      B+\n",
       "2105  34.2       A\n",
       "2201  39.1       B\n",
       "2202  68.5      B+\n",
       "2203  73.8      A+\n",
       "2204  47.2      B-\n",
       "2205  85.4       B\n",
       "2301  72.3      B+\n",
       "2302  32.7       A\n",
       "2303  65.9       C\n",
       "2304  95.5      A-\n",
       "2305  48.9       B\n",
       "2401  45.3       A\n",
       "2402  48.7       B\n",
       "2403  59.7      B+\n",
       "2404  67.7       B\n",
       "2405  47.6       B"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[lambda x:['Math','Physics']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>School</th>\n",
       "      <th>Class</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Address</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1102</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>192</td>\n",
       "      <td>73</td>\n",
       "      <td>32.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1104</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>167</td>\n",
       "      <td>81</td>\n",
       "      <td>80.4</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2401</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>192</td>\n",
       "      <td>62</td>\n",
       "      <td>45.3</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2404</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>160</td>\n",
       "      <td>84</td>\n",
       "      <td>67.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     School Class Gender   Address  Height  Weight  Math Physics\n",
       "ID                                                              \n",
       "1102    S_1   C_1      F  street_2     192      73  32.5      B+\n",
       "1104    S_1   C_1      F  street_2     167      81  80.4      B-\n",
       "2401    S_2   C_4      F  street_2     192      62  45.3       A\n",
       "2404    S_2   C_4      F  street_2     160      84  67.7       B"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[(df['Gender']=='F')&(df['Address']=='street_2')]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "isin代表查询在哪个范围"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>School</th>\n",
       "      <th>Class</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Address</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1101</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_1</td>\n",
       "      <td>173</td>\n",
       "      <td>63</td>\n",
       "      <td>34.0</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1105</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_4</td>\n",
       "      <td>159</td>\n",
       "      <td>64</td>\n",
       "      <td>84.8</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1202</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_4</td>\n",
       "      <td>176</td>\n",
       "      <td>94</td>\n",
       "      <td>63.5</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1301</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>161</td>\n",
       "      <td>68</td>\n",
       "      <td>31.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1302</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_1</td>\n",
       "      <td>175</td>\n",
       "      <td>57</td>\n",
       "      <td>87.7</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2103</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>157</td>\n",
       "      <td>61</td>\n",
       "      <td>52.5</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2105</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>170</td>\n",
       "      <td>81</td>\n",
       "      <td>34.2</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2203</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>155</td>\n",
       "      <td>91</td>\n",
       "      <td>73.8</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2204</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_1</td>\n",
       "      <td>175</td>\n",
       "      <td>74</td>\n",
       "      <td>47.2</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2301</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_4</td>\n",
       "      <td>157</td>\n",
       "      <td>78</td>\n",
       "      <td>72.3</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2305</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>187</td>\n",
       "      <td>73</td>\n",
       "      <td>48.9</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     School Class Gender   Address  Height  Weight  Math Physics\n",
       "ID                                                              \n",
       "1101    S_1   C_1      M  street_1     173      63  34.0      A+\n",
       "1105    S_1   C_1      F  street_4     159      64  84.8      B+\n",
       "1202    S_1   C_2      F  street_4     176      94  63.5      B-\n",
       "1301    S_1   C_3      M  street_4     161      68  31.5      B+\n",
       "1302    S_1   C_3      F  street_1     175      57  87.7      A-\n",
       "2103    S_2   C_1      M  street_4     157      61  52.5      B-\n",
       "2105    S_2   C_1      M  street_4     170      81  34.2       A\n",
       "2203    S_2   C_2      M  street_4     155      91  73.8      A+\n",
       "2204    S_2   C_2      M  street_1     175      74  47.2      B-\n",
       "2301    S_2   C_3      F  street_4     157      78  72.3      B+\n",
       "2305    S_2   C_3      M  street_4     187      73  48.9       B"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[df['Address'].isin(['street_1','street_4'])]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "快速标量（定位到某一个索引）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'S_1'"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[0,0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>School</th>\n",
       "      <th>Class</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Address</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1101</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_1</td>\n",
       "      <td>173</td>\n",
       "      <td>63</td>\n",
       "      <td>34.0</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1102</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>192</td>\n",
       "      <td>73</td>\n",
       "      <td>32.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1103</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_2</td>\n",
       "      <td>186</td>\n",
       "      <td>82</td>\n",
       "      <td>87.2</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1104</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>167</td>\n",
       "      <td>81</td>\n",
       "      <td>80.4</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1105</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_4</td>\n",
       "      <td>159</td>\n",
       "      <td>64</td>\n",
       "      <td>84.8</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1201</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_5</td>\n",
       "      <td>188</td>\n",
       "      <td>68</td>\n",
       "      <td>97.0</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1202</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_4</td>\n",
       "      <td>176</td>\n",
       "      <td>94</td>\n",
       "      <td>63.5</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1203</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_6</td>\n",
       "      <td>160</td>\n",
       "      <td>53</td>\n",
       "      <td>58.8</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1204</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_5</td>\n",
       "      <td>162</td>\n",
       "      <td>63</td>\n",
       "      <td>33.8</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1205</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>167</td>\n",
       "      <td>63</td>\n",
       "      <td>68.4</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1301</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>161</td>\n",
       "      <td>68</td>\n",
       "      <td>31.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1302</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_1</td>\n",
       "      <td>175</td>\n",
       "      <td>57</td>\n",
       "      <td>87.7</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1303</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>188</td>\n",
       "      <td>82</td>\n",
       "      <td>49.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1304</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_2</td>\n",
       "      <td>195</td>\n",
       "      <td>70</td>\n",
       "      <td>85.2</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1305</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_5</td>\n",
       "      <td>187</td>\n",
       "      <td>69</td>\n",
       "      <td>61.7</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2101</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>174</td>\n",
       "      <td>84</td>\n",
       "      <td>83.3</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2102</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>161</td>\n",
       "      <td>61</td>\n",
       "      <td>50.6</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2103</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>157</td>\n",
       "      <td>61</td>\n",
       "      <td>52.5</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2104</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_5</td>\n",
       "      <td>159</td>\n",
       "      <td>97</td>\n",
       "      <td>72.2</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2105</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>170</td>\n",
       "      <td>81</td>\n",
       "      <td>34.2</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2201</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_5</td>\n",
       "      <td>193</td>\n",
       "      <td>100</td>\n",
       "      <td>39.1</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2202</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_7</td>\n",
       "      <td>194</td>\n",
       "      <td>77</td>\n",
       "      <td>68.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2203</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>155</td>\n",
       "      <td>91</td>\n",
       "      <td>73.8</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2204</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_1</td>\n",
       "      <td>175</td>\n",
       "      <td>74</td>\n",
       "      <td>47.2</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2205</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_7</td>\n",
       "      <td>183</td>\n",
       "      <td>76</td>\n",
       "      <td>85.4</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2301</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_4</td>\n",
       "      <td>157</td>\n",
       "      <td>78</td>\n",
       "      <td>72.3</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2302</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_5</td>\n",
       "      <td>171</td>\n",
       "      <td>88</td>\n",
       "      <td>32.7</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2303</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_7</td>\n",
       "      <td>190</td>\n",
       "      <td>99</td>\n",
       "      <td>65.9</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2304</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>164</td>\n",
       "      <td>81</td>\n",
       "      <td>95.5</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2305</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>187</td>\n",
       "      <td>73</td>\n",
       "      <td>48.9</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2401</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>192</td>\n",
       "      <td>62</td>\n",
       "      <td>45.3</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2402</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>166</td>\n",
       "      <td>82</td>\n",
       "      <td>48.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2403</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>158</td>\n",
       "      <td>60</td>\n",
       "      <td>59.7</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2404</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>160</td>\n",
       "      <td>84</td>\n",
       "      <td>67.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2405</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>193</td>\n",
       "      <td>54</td>\n",
       "      <td>47.6</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     School Class Gender   Address  Height  Weight  Math Physics\n",
       "ID                                                              \n",
       "1101    S_1   C_1      M  street_1     173      63  34.0      A+\n",
       "1102    S_1   C_1      F  street_2     192      73  32.5      B+\n",
       "1103    S_1   C_1      M  street_2     186      82  87.2      B+\n",
       "1104    S_1   C_1      F  street_2     167      81  80.4      B-\n",
       "1105    S_1   C_1      F  street_4     159      64  84.8      B+\n",
       "1201    S_1   C_2      M  street_5     188      68  97.0      A-\n",
       "1202    S_1   C_2      F  street_4     176      94  63.5      B-\n",
       "1203    S_1   C_2      M  street_6     160      53  58.8      A+\n",
       "1204    S_1   C_2      F  street_5     162      63  33.8       B\n",
       "1205    S_1   C_2      F  street_6     167      63  68.4      B-\n",
       "1301    S_1   C_3      M  street_4     161      68  31.5      B+\n",
       "1302    S_1   C_3      F  street_1     175      57  87.7      A-\n",
       "1303    S_1   C_3      M  street_7     188      82  49.7       B\n",
       "1304    S_1   C_3      M  street_2     195      70  85.2       A\n",
       "1305    S_1   C_3      F  street_5     187      69  61.7      B-\n",
       "2101    S_2   C_1      M  street_7     174      84  83.3       C\n",
       "2102    S_2   C_1      F  street_6     161      61  50.6      B+\n",
       "2103    S_2   C_1      M  street_4     157      61  52.5      B-\n",
       "2104    S_2   C_1      F  street_5     159      97  72.2      B+\n",
       "2105    S_2   C_1      M  street_4     170      81  34.2       A\n",
       "2201    S_2   C_2      M  street_5     193     100  39.1       B\n",
       "2202    S_2   C_2      F  street_7     194      77  68.5      B+\n",
       "2203    S_2   C_2      M  street_4     155      91  73.8      A+\n",
       "2204    S_2   C_2      M  street_1     175      74  47.2      B-\n",
       "2205    S_2   C_2      F  street_7     183      76  85.4       B\n",
       "2301    S_2   C_3      F  street_4     157      78  72.3      B+\n",
       "2302    S_2   C_3      M  street_5     171      88  32.7       A\n",
       "2303    S_2   C_3      F  street_7     190      99  65.9       C\n",
       "2304    S_2   C_3      F  street_6     164      81  95.5      A-\n",
       "2305    S_2   C_3      M  street_4     187      73  48.9       B\n",
       "2401    S_2   C_4      F  street_2     192      62  45.3       A\n",
       "2402    S_2   C_4      M  street_7     166      82  48.7       B\n",
       "2403    S_2   C_4      F  street_6     158      60  59.7      B+\n",
       "2404    S_2   C_4      F  street_2     160      84  67.7       B\n",
       "2405    S_2   C_4      F  street_6     193      54  47.6       B"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "利用cut函数将连续数据进行分层"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ID\n",
       "1101      (0, 60]\n",
       "1102      (0, 60]\n",
       "1103    (80, 100]\n",
       "1104    (80, 100]\n",
       "1105    (80, 100]\n",
       "1201    (80, 100]\n",
       "1202     (60, 80]\n",
       "1203      (0, 60]\n",
       "1204      (0, 60]\n",
       "1205     (60, 80]\n",
       "1301      (0, 60]\n",
       "1302    (80, 100]\n",
       "1303      (0, 60]\n",
       "1304    (80, 100]\n",
       "1305     (60, 80]\n",
       "2101    (80, 100]\n",
       "2102      (0, 60]\n",
       "2103      (0, 60]\n",
       "2104     (60, 80]\n",
       "2105      (0, 60]\n",
       "2201      (0, 60]\n",
       "2202     (60, 80]\n",
       "2203     (60, 80]\n",
       "2204      (0, 60]\n",
       "2205    (80, 100]\n",
       "2301     (60, 80]\n",
       "2302      (0, 60]\n",
       "2303     (60, 80]\n",
       "2304    (80, 100]\n",
       "2305      (0, 60]\n",
       "2401      (0, 60]\n",
       "2402      (0, 60]\n",
       "2403      (0, 60]\n",
       "2404     (60, 80]\n",
       "2405      (0, 60]\n",
       "Name: Math, dtype: category\n",
       "Categories (3, interval[int64]): [(0, 60] < (60, 80] < (80, 100]]"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "math_interval = pd.cut(df['Math'],bins=[0,60,80,100])\n",
    "math_interval"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>School</th>\n",
       "      <th>Class</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Address</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1101</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_1</td>\n",
       "      <td>173</td>\n",
       "      <td>63</td>\n",
       "      <td>34.0</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1102</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>192</td>\n",
       "      <td>73</td>\n",
       "      <td>32.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1103</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_2</td>\n",
       "      <td>186</td>\n",
       "      <td>82</td>\n",
       "      <td>87.2</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1104</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>167</td>\n",
       "      <td>81</td>\n",
       "      <td>80.4</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1105</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_4</td>\n",
       "      <td>159</td>\n",
       "      <td>64</td>\n",
       "      <td>84.8</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     School Class Gender   Address  Height  Weight  Math Physics\n",
       "ID                                                              \n",
       "1101    S_1   C_1      M  street_1     173      63  34.0      A+\n",
       "1102    S_1   C_1      F  street_2     192      73  32.5      B+\n",
       "1103    S_1   C_1      M  street_2     186      82  87.2      B+\n",
       "1104    S_1   C_1      F  street_2     167      81  80.4      B-\n",
       "1105    S_1   C_1      F  street_4     159      64  84.8      B+"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "区间索引的选取 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_i = df.join(math_interval,rsuffix='_interval')[['Math','Math_interval']]\\\n",
    "            .reset_index().set_index('Math_interval')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "多级索引 \n",
    "1：直接通过元组来进行创建(利用zip创建元组)\n",
    "2：通过from_product函数创建\n",
    "3:df.set_index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "MultiIndex(levels=[['A', 'B'], ['a', 'b']],\n",
       "           codes=[[0, 0, 1, 1], [0, 1, 0, 1]],\n",
       "           names=['Upper', 'Lower'])"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tuples = [('A','a'),('A','b'),('B','a'),('B','b')]\n",
    "mul_index = pd.MultiIndex.from_tuples(tuples, names=('Upper', 'Lower'))\n",
    "mul_index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Score</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Upper</th>\n",
       "      <th>Lower</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">A</th>\n",
       "      <th>a</th>\n",
       "      <td>perfect</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>b</th>\n",
       "      <td>good</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">B</th>\n",
       "      <th>a</th>\n",
       "      <td>fair</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>b</th>\n",
       "      <td>bad</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               Score\n",
       "Upper Lower         \n",
       "A     a      perfect\n",
       "      b         good\n",
       "B     a         fair\n",
       "      b          bad"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame({'Score':['perfect','good','fair','bad']},index=mul_index)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Score</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Upper</th>\n",
       "      <th>Lower</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">A</th>\n",
       "      <th>a</th>\n",
       "      <td>perfect</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>b</th>\n",
       "      <td>good</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">B</th>\n",
       "      <th>a</th>\n",
       "      <td>fair</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>b</th>\n",
       "      <td>bad</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               Score\n",
       "Upper Lower         \n",
       "A     a      perfect\n",
       "      b         good\n",
       "B     a         fair\n",
       "      b          bad"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "L1 = list('AABB')\n",
    "L2 = list('abab')\n",
    "tuples = list(zip(L1,L2))\n",
    "mul_index = pd.MultiIndex.from_tuples(tuples, names=('Upper', 'Lower'))\n",
    "pd.DataFrame({'Score':['perfect','good','fair','bad']},index=mul_index)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>School</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Class</th>\n",
       "      <th>Address</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">C_1</th>\n",
       "      <th>street_1</th>\n",
       "      <td>S_1</td>\n",
       "      <td>M</td>\n",
       "      <td>173</td>\n",
       "      <td>63</td>\n",
       "      <td>34.0</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_2</th>\n",
       "      <td>S_1</td>\n",
       "      <td>F</td>\n",
       "      <td>192</td>\n",
       "      <td>73</td>\n",
       "      <td>32.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_2</th>\n",
       "      <td>S_1</td>\n",
       "      <td>M</td>\n",
       "      <td>186</td>\n",
       "      <td>82</td>\n",
       "      <td>87.2</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_2</th>\n",
       "      <td>S_1</td>\n",
       "      <td>F</td>\n",
       "      <td>167</td>\n",
       "      <td>81</td>\n",
       "      <td>80.4</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_4</th>\n",
       "      <td>S_1</td>\n",
       "      <td>F</td>\n",
       "      <td>159</td>\n",
       "      <td>64</td>\n",
       "      <td>84.8</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               School Gender  Height  Weight  Math Physics\n",
       "Class Address                                             \n",
       "C_1   street_1    S_1      M     173      63  34.0      A+\n",
       "      street_2    S_1      F     192      73  32.5      B+\n",
       "      street_2    S_1      M     186      82  87.2      B+\n",
       "      street_2    S_1      F     167      81  80.4      B-\n",
       "      street_4    S_1      F     159      64  84.8      B+"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_using_mul = df.set_index(['Class','Address'])\n",
    "df_using_mul.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>School</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Class</th>\n",
       "      <th>Address</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">C_2</th>\n",
       "      <th>street_4</th>\n",
       "      <td>S_1</td>\n",
       "      <td>F</td>\n",
       "      <td>176</td>\n",
       "      <td>94</td>\n",
       "      <td>63.5</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_4</th>\n",
       "      <td>S_2</td>\n",
       "      <td>M</td>\n",
       "      <td>155</td>\n",
       "      <td>91</td>\n",
       "      <td>73.8</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               School Gender  Height  Weight  Math Physics\n",
       "Class Address                                             \n",
       "C_2   street_4    S_1      F     176      94  63.5      B-\n",
       "      street_4    S_2      M     155      91  73.8      A+"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#一般切片 在进行切片前 必须要进行排序\n",
    "df_using_mul.sort_index().loc['C_2','street_4']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>School</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Class</th>\n",
       "      <th>Address</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"4\" valign=\"top\">C_2</th>\n",
       "      <th>street_6</th>\n",
       "      <td>S_1</td>\n",
       "      <td>M</td>\n",
       "      <td>160</td>\n",
       "      <td>53</td>\n",
       "      <td>58.8</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_6</th>\n",
       "      <td>S_1</td>\n",
       "      <td>F</td>\n",
       "      <td>167</td>\n",
       "      <td>63</td>\n",
       "      <td>68.4</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_7</th>\n",
       "      <td>S_2</td>\n",
       "      <td>F</td>\n",
       "      <td>194</td>\n",
       "      <td>77</td>\n",
       "      <td>68.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_7</th>\n",
       "      <td>S_2</td>\n",
       "      <td>F</td>\n",
       "      <td>183</td>\n",
       "      <td>76</td>\n",
       "      <td>85.4</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">C_3</th>\n",
       "      <th>street_1</th>\n",
       "      <td>S_1</td>\n",
       "      <td>F</td>\n",
       "      <td>175</td>\n",
       "      <td>57</td>\n",
       "      <td>87.7</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_2</th>\n",
       "      <td>S_1</td>\n",
       "      <td>M</td>\n",
       "      <td>195</td>\n",
       "      <td>70</td>\n",
       "      <td>85.2</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_4</th>\n",
       "      <td>S_1</td>\n",
       "      <td>M</td>\n",
       "      <td>161</td>\n",
       "      <td>68</td>\n",
       "      <td>31.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_4</th>\n",
       "      <td>S_2</td>\n",
       "      <td>F</td>\n",
       "      <td>157</td>\n",
       "      <td>78</td>\n",
       "      <td>72.3</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_4</th>\n",
       "      <td>S_2</td>\n",
       "      <td>M</td>\n",
       "      <td>187</td>\n",
       "      <td>73</td>\n",
       "      <td>48.9</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               School Gender  Height  Weight  Math Physics\n",
       "Class Address                                             \n",
       "C_2   street_6    S_1      M     160      53  58.8      A+\n",
       "      street_6    S_1      F     167      63  68.4      B-\n",
       "      street_7    S_2      F     194      77  68.5      B+\n",
       "      street_7    S_2      F     183      76  85.4       B\n",
       "C_3   street_1    S_1      F     175      57  87.7      A-\n",
       "      street_2    S_1      M     195      70  85.2       A\n",
       "      street_4    S_1      M     161      68  31.5      B+\n",
       "      street_4    S_2      F     157      78  72.3      B+\n",
       "      street_4    S_2      M     187      73  48.9       B"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#多层切片 在进行切片前 必须要进行排序 由元组构成列表的情况 精确到最内层索引\n",
    "df_using_mul.sort_index().loc[('C_2','street_6'):('C_3','street_4')]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>School</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Class</th>\n",
       "      <th>Address</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"4\" valign=\"top\">C_2</th>\n",
       "      <th>street_4</th>\n",
       "      <td>S_1</td>\n",
       "      <td>F</td>\n",
       "      <td>176</td>\n",
       "      <td>94</td>\n",
       "      <td>63.5</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_4</th>\n",
       "      <td>S_2</td>\n",
       "      <td>M</td>\n",
       "      <td>155</td>\n",
       "      <td>91</td>\n",
       "      <td>73.8</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_7</th>\n",
       "      <td>S_2</td>\n",
       "      <td>F</td>\n",
       "      <td>194</td>\n",
       "      <td>77</td>\n",
       "      <td>68.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_7</th>\n",
       "      <td>S_2</td>\n",
       "      <td>F</td>\n",
       "      <td>183</td>\n",
       "      <td>76</td>\n",
       "      <td>85.4</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">C_3</th>\n",
       "      <th>street_4</th>\n",
       "      <td>S_1</td>\n",
       "      <td>M</td>\n",
       "      <td>161</td>\n",
       "      <td>68</td>\n",
       "      <td>31.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_4</th>\n",
       "      <td>S_2</td>\n",
       "      <td>F</td>\n",
       "      <td>157</td>\n",
       "      <td>78</td>\n",
       "      <td>72.3</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_4</th>\n",
       "      <td>S_2</td>\n",
       "      <td>M</td>\n",
       "      <td>187</td>\n",
       "      <td>73</td>\n",
       "      <td>48.9</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_7</th>\n",
       "      <td>S_1</td>\n",
       "      <td>M</td>\n",
       "      <td>188</td>\n",
       "      <td>82</td>\n",
       "      <td>49.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_7</th>\n",
       "      <td>S_2</td>\n",
       "      <td>F</td>\n",
       "      <td>190</td>\n",
       "      <td>99</td>\n",
       "      <td>65.9</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               School Gender  Height  Weight  Math Physics\n",
       "Class Address                                             \n",
       "C_2   street_4    S_1      F     176      94  63.5      B-\n",
       "      street_4    S_2      M     155      91  73.8      A+\n",
       "      street_7    S_2      F     194      77  68.5      B+\n",
       "      street_7    S_2      F     183      76  85.4       B\n",
       "C_3   street_4    S_1      M     161      68  31.5      B+\n",
       "      street_4    S_2      F     157      78  72.3      B+\n",
       "      street_4    S_2      M     187      73  48.9       B\n",
       "      street_7    S_1      M     188      82  49.7       B\n",
       "      street_7    S_2      F     190      99  65.9       C"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#由列表构成元组的情况\n",
    "df_using_mul.sort_index().loc[(['C_2','C_3'],['street_4','street_7']),:]\n",
    "#选出第一层在‘C_2’和'C_3'中且第二层在'street_4'和'street_7'中的行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>Big</th>\n",
       "      <th colspan=\"3\" halign=\"left\">D</th>\n",
       "      <th colspan=\"3\" halign=\"left\">E</th>\n",
       "      <th colspan=\"3\" halign=\"left\">F</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>Small</th>\n",
       "      <th>d</th>\n",
       "      <th>e</th>\n",
       "      <th>f</th>\n",
       "      <th>d</th>\n",
       "      <th>e</th>\n",
       "      <th>f</th>\n",
       "      <th>d</th>\n",
       "      <th>e</th>\n",
       "      <th>f</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Upper</th>\n",
       "      <th>Lower</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">A</th>\n",
       "      <th>a</th>\n",
       "      <td>0.460364</td>\n",
       "      <td>0.798035</td>\n",
       "      <td>0.624468</td>\n",
       "      <td>0.971249</td>\n",
       "      <td>0.580959</td>\n",
       "      <td>0.472398</td>\n",
       "      <td>0.165656</td>\n",
       "      <td>0.686437</td>\n",
       "      <td>0.071474</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>b</th>\n",
       "      <td>0.445650</td>\n",
       "      <td>0.665985</td>\n",
       "      <td>0.356289</td>\n",
       "      <td>0.311397</td>\n",
       "      <td>0.221256</td>\n",
       "      <td>0.885369</td>\n",
       "      <td>0.732994</td>\n",
       "      <td>0.125133</td>\n",
       "      <td>0.362034</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>0.893712</td>\n",
       "      <td>0.948795</td>\n",
       "      <td>0.846103</td>\n",
       "      <td>0.816995</td>\n",
       "      <td>0.992387</td>\n",
       "      <td>0.460335</td>\n",
       "      <td>0.106104</td>\n",
       "      <td>0.602991</td>\n",
       "      <td>0.399719</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">B</th>\n",
       "      <th>a</th>\n",
       "      <td>0.833477</td>\n",
       "      <td>0.354645</td>\n",
       "      <td>0.846314</td>\n",
       "      <td>0.850676</td>\n",
       "      <td>0.622730</td>\n",
       "      <td>0.342718</td>\n",
       "      <td>0.120181</td>\n",
       "      <td>0.823666</td>\n",
       "      <td>0.117466</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>b</th>\n",
       "      <td>0.417886</td>\n",
       "      <td>0.450450</td>\n",
       "      <td>0.198988</td>\n",
       "      <td>0.010317</td>\n",
       "      <td>0.944665</td>\n",
       "      <td>0.895454</td>\n",
       "      <td>0.607168</td>\n",
       "      <td>0.016710</td>\n",
       "      <td>0.907578</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>0.826945</td>\n",
       "      <td>0.588846</td>\n",
       "      <td>0.353248</td>\n",
       "      <td>0.759625</td>\n",
       "      <td>0.030753</td>\n",
       "      <td>0.050414</td>\n",
       "      <td>0.342283</td>\n",
       "      <td>0.722593</td>\n",
       "      <td>0.660445</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">C</th>\n",
       "      <th>a</th>\n",
       "      <td>0.604627</td>\n",
       "      <td>0.139398</td>\n",
       "      <td>0.922738</td>\n",
       "      <td>0.114463</td>\n",
       "      <td>0.604331</td>\n",
       "      <td>0.692255</td>\n",
       "      <td>0.286099</td>\n",
       "      <td>0.538040</td>\n",
       "      <td>0.461744</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>b</th>\n",
       "      <td>0.758036</td>\n",
       "      <td>0.515492</td>\n",
       "      <td>0.122043</td>\n",
       "      <td>0.134327</td>\n",
       "      <td>0.723696</td>\n",
       "      <td>0.071618</td>\n",
       "      <td>0.184698</td>\n",
       "      <td>0.446830</td>\n",
       "      <td>0.618517</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>0.245225</td>\n",
       "      <td>0.955709</td>\n",
       "      <td>0.686017</td>\n",
       "      <td>0.415903</td>\n",
       "      <td>0.809549</td>\n",
       "      <td>0.835083</td>\n",
       "      <td>0.886895</td>\n",
       "      <td>0.242803</td>\n",
       "      <td>0.815168</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Big                 D                             E                      \\\n",
       "Small               d         e         f         d         e         f   \n",
       "Upper Lower                                                               \n",
       "A     a      0.460364  0.798035  0.624468  0.971249  0.580959  0.472398   \n",
       "      b      0.445650  0.665985  0.356289  0.311397  0.221256  0.885369   \n",
       "      c      0.893712  0.948795  0.846103  0.816995  0.992387  0.460335   \n",
       "B     a      0.833477  0.354645  0.846314  0.850676  0.622730  0.342718   \n",
       "      b      0.417886  0.450450  0.198988  0.010317  0.944665  0.895454   \n",
       "      c      0.826945  0.588846  0.353248  0.759625  0.030753  0.050414   \n",
       "C     a      0.604627  0.139398  0.922738  0.114463  0.604331  0.692255   \n",
       "      b      0.758036  0.515492  0.122043  0.134327  0.723696  0.071618   \n",
       "      c      0.245225  0.955709  0.686017  0.415903  0.809549  0.835083   \n",
       "\n",
       "Big                 F                      \n",
       "Small               d         e         f  \n",
       "Upper Lower                                \n",
       "A     a      0.165656  0.686437  0.071474  \n",
       "      b      0.732994  0.125133  0.362034  \n",
       "      c      0.106104  0.602991  0.399719  \n",
       "B     a      0.120181  0.823666  0.117466  \n",
       "      b      0.607168  0.016710  0.907578  \n",
       "      c      0.342283  0.722593  0.660445  \n",
       "C     a      0.286099  0.538040  0.461744  \n",
       "      b      0.184698  0.446830  0.618517  \n",
       "      c      0.886895  0.242803  0.815168  "
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#行列索引都是多层 等用到了再学\n",
    "L1,L2 = ['A','B','C'],['a','b','c']\n",
    "mul_index1 = pd.MultiIndex.from_product([L1,L2],names=('Upper', 'Lower'))\n",
    "L3,L4 = ['D','E','F'],['d','e','f']\n",
    "mul_index2 = pd.MultiIndex.from_product([L3,L4],names=('Big', 'Small'))\n",
    "df_s = pd.DataFrame(np.random.rand(9,9),index=mul_index1,columns=mul_index2)\n",
    "df_s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>School</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Class</th>\n",
       "      <th>Address</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">C_1</th>\n",
       "      <th>street_1</th>\n",
       "      <td>S_1</td>\n",
       "      <td>M</td>\n",
       "      <td>173</td>\n",
       "      <td>63</td>\n",
       "      <td>34.0</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_2</th>\n",
       "      <td>S_1</td>\n",
       "      <td>F</td>\n",
       "      <td>192</td>\n",
       "      <td>73</td>\n",
       "      <td>32.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_2</th>\n",
       "      <td>S_1</td>\n",
       "      <td>M</td>\n",
       "      <td>186</td>\n",
       "      <td>82</td>\n",
       "      <td>87.2</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_2</th>\n",
       "      <td>S_1</td>\n",
       "      <td>F</td>\n",
       "      <td>167</td>\n",
       "      <td>81</td>\n",
       "      <td>80.4</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_4</th>\n",
       "      <td>S_1</td>\n",
       "      <td>F</td>\n",
       "      <td>159</td>\n",
       "      <td>64</td>\n",
       "      <td>84.8</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">C_2</th>\n",
       "      <th>street_5</th>\n",
       "      <td>S_1</td>\n",
       "      <td>M</td>\n",
       "      <td>188</td>\n",
       "      <td>68</td>\n",
       "      <td>97.0</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_4</th>\n",
       "      <td>S_1</td>\n",
       "      <td>F</td>\n",
       "      <td>176</td>\n",
       "      <td>94</td>\n",
       "      <td>63.5</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_6</th>\n",
       "      <td>S_1</td>\n",
       "      <td>M</td>\n",
       "      <td>160</td>\n",
       "      <td>53</td>\n",
       "      <td>58.8</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_5</th>\n",
       "      <td>S_1</td>\n",
       "      <td>F</td>\n",
       "      <td>162</td>\n",
       "      <td>63</td>\n",
       "      <td>33.8</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_6</th>\n",
       "      <td>S_1</td>\n",
       "      <td>F</td>\n",
       "      <td>167</td>\n",
       "      <td>63</td>\n",
       "      <td>68.4</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">C_3</th>\n",
       "      <th>street_4</th>\n",
       "      <td>S_1</td>\n",
       "      <td>M</td>\n",
       "      <td>161</td>\n",
       "      <td>68</td>\n",
       "      <td>31.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_1</th>\n",
       "      <td>S_1</td>\n",
       "      <td>F</td>\n",
       "      <td>175</td>\n",
       "      <td>57</td>\n",
       "      <td>87.7</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_7</th>\n",
       "      <td>S_1</td>\n",
       "      <td>M</td>\n",
       "      <td>188</td>\n",
       "      <td>82</td>\n",
       "      <td>49.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_2</th>\n",
       "      <td>S_1</td>\n",
       "      <td>M</td>\n",
       "      <td>195</td>\n",
       "      <td>70</td>\n",
       "      <td>85.2</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_5</th>\n",
       "      <td>S_1</td>\n",
       "      <td>F</td>\n",
       "      <td>187</td>\n",
       "      <td>69</td>\n",
       "      <td>61.7</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">C_1</th>\n",
       "      <th>street_7</th>\n",
       "      <td>S_2</td>\n",
       "      <td>M</td>\n",
       "      <td>174</td>\n",
       "      <td>84</td>\n",
       "      <td>83.3</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_6</th>\n",
       "      <td>S_2</td>\n",
       "      <td>F</td>\n",
       "      <td>161</td>\n",
       "      <td>61</td>\n",
       "      <td>50.6</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_4</th>\n",
       "      <td>S_2</td>\n",
       "      <td>M</td>\n",
       "      <td>157</td>\n",
       "      <td>61</td>\n",
       "      <td>52.5</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_5</th>\n",
       "      <td>S_2</td>\n",
       "      <td>F</td>\n",
       "      <td>159</td>\n",
       "      <td>97</td>\n",
       "      <td>72.2</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_4</th>\n",
       "      <td>S_2</td>\n",
       "      <td>M</td>\n",
       "      <td>170</td>\n",
       "      <td>81</td>\n",
       "      <td>34.2</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">C_2</th>\n",
       "      <th>street_5</th>\n",
       "      <td>S_2</td>\n",
       "      <td>M</td>\n",
       "      <td>193</td>\n",
       "      <td>100</td>\n",
       "      <td>39.1</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_7</th>\n",
       "      <td>S_2</td>\n",
       "      <td>F</td>\n",
       "      <td>194</td>\n",
       "      <td>77</td>\n",
       "      <td>68.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_4</th>\n",
       "      <td>S_2</td>\n",
       "      <td>M</td>\n",
       "      <td>155</td>\n",
       "      <td>91</td>\n",
       "      <td>73.8</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_1</th>\n",
       "      <td>S_2</td>\n",
       "      <td>M</td>\n",
       "      <td>175</td>\n",
       "      <td>74</td>\n",
       "      <td>47.2</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_7</th>\n",
       "      <td>S_2</td>\n",
       "      <td>F</td>\n",
       "      <td>183</td>\n",
       "      <td>76</td>\n",
       "      <td>85.4</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">C_3</th>\n",
       "      <th>street_4</th>\n",
       "      <td>S_2</td>\n",
       "      <td>F</td>\n",
       "      <td>157</td>\n",
       "      <td>78</td>\n",
       "      <td>72.3</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_5</th>\n",
       "      <td>S_2</td>\n",
       "      <td>M</td>\n",
       "      <td>171</td>\n",
       "      <td>88</td>\n",
       "      <td>32.7</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_7</th>\n",
       "      <td>S_2</td>\n",
       "      <td>F</td>\n",
       "      <td>190</td>\n",
       "      <td>99</td>\n",
       "      <td>65.9</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_6</th>\n",
       "      <td>S_2</td>\n",
       "      <td>F</td>\n",
       "      <td>164</td>\n",
       "      <td>81</td>\n",
       "      <td>95.5</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_4</th>\n",
       "      <td>S_2</td>\n",
       "      <td>M</td>\n",
       "      <td>187</td>\n",
       "      <td>73</td>\n",
       "      <td>48.9</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">C_4</th>\n",
       "      <th>street_2</th>\n",
       "      <td>S_2</td>\n",
       "      <td>F</td>\n",
       "      <td>192</td>\n",
       "      <td>62</td>\n",
       "      <td>45.3</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_7</th>\n",
       "      <td>S_2</td>\n",
       "      <td>M</td>\n",
       "      <td>166</td>\n",
       "      <td>82</td>\n",
       "      <td>48.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_6</th>\n",
       "      <td>S_2</td>\n",
       "      <td>F</td>\n",
       "      <td>158</td>\n",
       "      <td>60</td>\n",
       "      <td>59.7</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_2</th>\n",
       "      <td>S_2</td>\n",
       "      <td>F</td>\n",
       "      <td>160</td>\n",
       "      <td>84</td>\n",
       "      <td>67.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_6</th>\n",
       "      <td>S_2</td>\n",
       "      <td>F</td>\n",
       "      <td>193</td>\n",
       "      <td>54</td>\n",
       "      <td>47.6</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               School Gender  Height  Weight  Math Physics\n",
       "Class Address                                             \n",
       "C_1   street_1    S_1      M     173      63  34.0      A+\n",
       "      street_2    S_1      F     192      73  32.5      B+\n",
       "      street_2    S_1      M     186      82  87.2      B+\n",
       "      street_2    S_1      F     167      81  80.4      B-\n",
       "      street_4    S_1      F     159      64  84.8      B+\n",
       "C_2   street_5    S_1      M     188      68  97.0      A-\n",
       "      street_4    S_1      F     176      94  63.5      B-\n",
       "      street_6    S_1      M     160      53  58.8      A+\n",
       "      street_5    S_1      F     162      63  33.8       B\n",
       "      street_6    S_1      F     167      63  68.4      B-\n",
       "C_3   street_4    S_1      M     161      68  31.5      B+\n",
       "      street_1    S_1      F     175      57  87.7      A-\n",
       "      street_7    S_1      M     188      82  49.7       B\n",
       "      street_2    S_1      M     195      70  85.2       A\n",
       "      street_5    S_1      F     187      69  61.7      B-\n",
       "C_1   street_7    S_2      M     174      84  83.3       C\n",
       "      street_6    S_2      F     161      61  50.6      B+\n",
       "      street_4    S_2      M     157      61  52.5      B-\n",
       "      street_5    S_2      F     159      97  72.2      B+\n",
       "      street_4    S_2      M     170      81  34.2       A\n",
       "C_2   street_5    S_2      M     193     100  39.1       B\n",
       "      street_7    S_2      F     194      77  68.5      B+\n",
       "      street_4    S_2      M     155      91  73.8      A+\n",
       "      street_1    S_2      M     175      74  47.2      B-\n",
       "      street_7    S_2      F     183      76  85.4       B\n",
       "C_3   street_4    S_2      F     157      78  72.3      B+\n",
       "      street_5    S_2      M     171      88  32.7       A\n",
       "      street_7    S_2      F     190      99  65.9       C\n",
       "      street_6    S_2      F     164      81  95.5      A-\n",
       "      street_4    S_2      M     187      73  48.9       B\n",
       "C_4   street_2    S_2      F     192      62  45.3       A\n",
       "      street_7    S_2      M     166      82  48.7       B\n",
       "      street_6    S_2      F     158      60  59.7      B+\n",
       "      street_2    S_2      F     160      84  67.7       B\n",
       "      street_6    S_2      F     193      54  47.6       B"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_using_mul"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "两层索引的位置进行交换"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>School</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Address</th>\n",
       "      <th>Class</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">street_1</th>\n",
       "      <th>C_1</th>\n",
       "      <td>S_1</td>\n",
       "      <td>M</td>\n",
       "      <td>173</td>\n",
       "      <td>63</td>\n",
       "      <td>34.0</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C_2</th>\n",
       "      <td>S_2</td>\n",
       "      <td>M</td>\n",
       "      <td>175</td>\n",
       "      <td>74</td>\n",
       "      <td>47.2</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C_3</th>\n",
       "      <td>S_1</td>\n",
       "      <td>F</td>\n",
       "      <td>175</td>\n",
       "      <td>57</td>\n",
       "      <td>87.7</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"6\" valign=\"top\">street_2</th>\n",
       "      <th>C_1</th>\n",
       "      <td>S_1</td>\n",
       "      <td>F</td>\n",
       "      <td>192</td>\n",
       "      <td>73</td>\n",
       "      <td>32.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C_1</th>\n",
       "      <td>S_1</td>\n",
       "      <td>M</td>\n",
       "      <td>186</td>\n",
       "      <td>82</td>\n",
       "      <td>87.2</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C_1</th>\n",
       "      <td>S_1</td>\n",
       "      <td>F</td>\n",
       "      <td>167</td>\n",
       "      <td>81</td>\n",
       "      <td>80.4</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C_3</th>\n",
       "      <td>S_1</td>\n",
       "      <td>M</td>\n",
       "      <td>195</td>\n",
       "      <td>70</td>\n",
       "      <td>85.2</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C_4</th>\n",
       "      <td>S_2</td>\n",
       "      <td>F</td>\n",
       "      <td>192</td>\n",
       "      <td>62</td>\n",
       "      <td>45.3</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C_4</th>\n",
       "      <td>S_2</td>\n",
       "      <td>F</td>\n",
       "      <td>160</td>\n",
       "      <td>84</td>\n",
       "      <td>67.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"8\" valign=\"top\">street_4</th>\n",
       "      <th>C_1</th>\n",
       "      <td>S_1</td>\n",
       "      <td>F</td>\n",
       "      <td>159</td>\n",
       "      <td>64</td>\n",
       "      <td>84.8</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C_1</th>\n",
       "      <td>S_2</td>\n",
       "      <td>M</td>\n",
       "      <td>157</td>\n",
       "      <td>61</td>\n",
       "      <td>52.5</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C_1</th>\n",
       "      <td>S_2</td>\n",
       "      <td>M</td>\n",
       "      <td>170</td>\n",
       "      <td>81</td>\n",
       "      <td>34.2</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C_2</th>\n",
       "      <td>S_1</td>\n",
       "      <td>F</td>\n",
       "      <td>176</td>\n",
       "      <td>94</td>\n",
       "      <td>63.5</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C_2</th>\n",
       "      <td>S_2</td>\n",
       "      <td>M</td>\n",
       "      <td>155</td>\n",
       "      <td>91</td>\n",
       "      <td>73.8</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C_3</th>\n",
       "      <td>S_1</td>\n",
       "      <td>M</td>\n",
       "      <td>161</td>\n",
       "      <td>68</td>\n",
       "      <td>31.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C_3</th>\n",
       "      <td>S_2</td>\n",
       "      <td>F</td>\n",
       "      <td>157</td>\n",
       "      <td>78</td>\n",
       "      <td>72.3</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C_3</th>\n",
       "      <td>S_2</td>\n",
       "      <td>M</td>\n",
       "      <td>187</td>\n",
       "      <td>73</td>\n",
       "      <td>48.9</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"6\" valign=\"top\">street_5</th>\n",
       "      <th>C_1</th>\n",
       "      <td>S_2</td>\n",
       "      <td>F</td>\n",
       "      <td>159</td>\n",
       "      <td>97</td>\n",
       "      <td>72.2</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C_2</th>\n",
       "      <td>S_1</td>\n",
       "      <td>M</td>\n",
       "      <td>188</td>\n",
       "      <td>68</td>\n",
       "      <td>97.0</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C_2</th>\n",
       "      <td>S_1</td>\n",
       "      <td>F</td>\n",
       "      <td>162</td>\n",
       "      <td>63</td>\n",
       "      <td>33.8</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C_2</th>\n",
       "      <td>S_2</td>\n",
       "      <td>M</td>\n",
       "      <td>193</td>\n",
       "      <td>100</td>\n",
       "      <td>39.1</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C_3</th>\n",
       "      <td>S_1</td>\n",
       "      <td>F</td>\n",
       "      <td>187</td>\n",
       "      <td>69</td>\n",
       "      <td>61.7</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C_3</th>\n",
       "      <td>S_2</td>\n",
       "      <td>M</td>\n",
       "      <td>171</td>\n",
       "      <td>88</td>\n",
       "      <td>32.7</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"6\" valign=\"top\">street_6</th>\n",
       "      <th>C_1</th>\n",
       "      <td>S_2</td>\n",
       "      <td>F</td>\n",
       "      <td>161</td>\n",
       "      <td>61</td>\n",
       "      <td>50.6</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C_2</th>\n",
       "      <td>S_1</td>\n",
       "      <td>M</td>\n",
       "      <td>160</td>\n",
       "      <td>53</td>\n",
       "      <td>58.8</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C_2</th>\n",
       "      <td>S_1</td>\n",
       "      <td>F</td>\n",
       "      <td>167</td>\n",
       "      <td>63</td>\n",
       "      <td>68.4</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C_3</th>\n",
       "      <td>S_2</td>\n",
       "      <td>F</td>\n",
       "      <td>164</td>\n",
       "      <td>81</td>\n",
       "      <td>95.5</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C_4</th>\n",
       "      <td>S_2</td>\n",
       "      <td>F</td>\n",
       "      <td>158</td>\n",
       "      <td>60</td>\n",
       "      <td>59.7</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C_4</th>\n",
       "      <td>S_2</td>\n",
       "      <td>F</td>\n",
       "      <td>193</td>\n",
       "      <td>54</td>\n",
       "      <td>47.6</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"6\" valign=\"top\">street_7</th>\n",
       "      <th>C_1</th>\n",
       "      <td>S_2</td>\n",
       "      <td>M</td>\n",
       "      <td>174</td>\n",
       "      <td>84</td>\n",
       "      <td>83.3</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C_2</th>\n",
       "      <td>S_2</td>\n",
       "      <td>F</td>\n",
       "      <td>194</td>\n",
       "      <td>77</td>\n",
       "      <td>68.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C_2</th>\n",
       "      <td>S_2</td>\n",
       "      <td>F</td>\n",
       "      <td>183</td>\n",
       "      <td>76</td>\n",
       "      <td>85.4</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C_3</th>\n",
       "      <td>S_1</td>\n",
       "      <td>M</td>\n",
       "      <td>188</td>\n",
       "      <td>82</td>\n",
       "      <td>49.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C_3</th>\n",
       "      <td>S_2</td>\n",
       "      <td>F</td>\n",
       "      <td>190</td>\n",
       "      <td>99</td>\n",
       "      <td>65.9</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C_4</th>\n",
       "      <td>S_2</td>\n",
       "      <td>M</td>\n",
       "      <td>166</td>\n",
       "      <td>82</td>\n",
       "      <td>48.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               School Gender  Height  Weight  Math Physics\n",
       "Address  Class                                            \n",
       "street_1 C_1      S_1      M     173      63  34.0      A+\n",
       "         C_2      S_2      M     175      74  47.2      B-\n",
       "         C_3      S_1      F     175      57  87.7      A-\n",
       "street_2 C_1      S_1      F     192      73  32.5      B+\n",
       "         C_1      S_1      M     186      82  87.2      B+\n",
       "         C_1      S_1      F     167      81  80.4      B-\n",
       "         C_3      S_1      M     195      70  85.2       A\n",
       "         C_4      S_2      F     192      62  45.3       A\n",
       "         C_4      S_2      F     160      84  67.7       B\n",
       "street_4 C_1      S_1      F     159      64  84.8      B+\n",
       "         C_1      S_2      M     157      61  52.5      B-\n",
       "         C_1      S_2      M     170      81  34.2       A\n",
       "         C_2      S_1      F     176      94  63.5      B-\n",
       "         C_2      S_2      M     155      91  73.8      A+\n",
       "         C_3      S_1      M     161      68  31.5      B+\n",
       "         C_3      S_2      F     157      78  72.3      B+\n",
       "         C_3      S_2      M     187      73  48.9       B\n",
       "street_5 C_1      S_2      F     159      97  72.2      B+\n",
       "         C_2      S_1      M     188      68  97.0      A-\n",
       "         C_2      S_1      F     162      63  33.8       B\n",
       "         C_2      S_2      M     193     100  39.1       B\n",
       "         C_3      S_1      F     187      69  61.7      B-\n",
       "         C_3      S_2      M     171      88  32.7       A\n",
       "street_6 C_1      S_2      F     161      61  50.6      B+\n",
       "         C_2      S_1      M     160      53  58.8      A+\n",
       "         C_2      S_1      F     167      63  68.4      B-\n",
       "         C_3      S_2      F     164      81  95.5      A-\n",
       "         C_4      S_2      F     158      60  59.7      B+\n",
       "         C_4      S_2      F     193      54  47.6       B\n",
       "street_7 C_1      S_2      M     174      84  83.3       C\n",
       "         C_2      S_2      F     194      77  68.5      B+\n",
       "         C_2      S_2      F     183      76  85.4       B\n",
       "         C_3      S_1      M     188      82  49.7       B\n",
       "         C_3      S_2      F     190      99  65.9       C\n",
       "         C_4      S_2      M     166      82  48.7       B"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_using_mul.swaplevel(i=1,j=0,axis=0).sort_index()\n",
    "#i j 代表第几层"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "索引设定"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Class</th>\n",
       "      <th>ID</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Address</th>\n",
       "      <th>School</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>street_1</th>\n",
       "      <th>S_1</th>\n",
       "      <td>C_1</td>\n",
       "      <td>1101</td>\n",
       "      <td>M</td>\n",
       "      <td>173</td>\n",
       "      <td>63</td>\n",
       "      <td>34.0</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">street_2</th>\n",
       "      <th>S_1</th>\n",
       "      <td>C_1</td>\n",
       "      <td>1102</td>\n",
       "      <td>F</td>\n",
       "      <td>192</td>\n",
       "      <td>73</td>\n",
       "      <td>32.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S_1</th>\n",
       "      <td>C_1</td>\n",
       "      <td>1103</td>\n",
       "      <td>M</td>\n",
       "      <td>186</td>\n",
       "      <td>82</td>\n",
       "      <td>87.2</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S_1</th>\n",
       "      <td>C_1</td>\n",
       "      <td>1104</td>\n",
       "      <td>F</td>\n",
       "      <td>167</td>\n",
       "      <td>81</td>\n",
       "      <td>80.4</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>street_4</th>\n",
       "      <th>S_1</th>\n",
       "      <td>C_1</td>\n",
       "      <td>1105</td>\n",
       "      <td>F</td>\n",
       "      <td>159</td>\n",
       "      <td>64</td>\n",
       "      <td>84.8</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                Class    ID Gender  Height  Weight  Math Physics\n",
       "Address  School                                                 \n",
       "street_1 S_1      C_1  1101      M     173      63  34.0      A+\n",
       "street_2 S_1      C_1  1102      F     192      73  32.5      B+\n",
       "         S_1      C_1  1103      M     186      82  87.2      B+\n",
       "         S_1      C_1  1104      F     167      81  80.4      B-\n",
       "street_4 S_1      C_1  1105      F     159      64  84.8      B+"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_csv('data/table.csv',index_col=['Address','School']).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>School</th>\n",
       "      <th>Class</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Address</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1101</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_1</td>\n",
       "      <td>173.0</td>\n",
       "      <td>63.0</td>\n",
       "      <td>34.0</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1203</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_6</td>\n",
       "      <td>160.0</td>\n",
       "      <td>53.0</td>\n",
       "      <td>58.8</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1206</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2402</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>166.0</td>\n",
       "      <td>82.0</td>\n",
       "      <td>48.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     School Class Gender   Address  Height  Weight  Math Physics\n",
       "ID                                                              \n",
       "1101    S_1   C_1      M  street_1   173.0    63.0  34.0      A+\n",
       "1203    S_1   C_2      M  street_6   160.0    53.0  58.8      A+\n",
       "1206    NaN   NaN    NaN       NaN     NaN     NaN   NaN     NaN\n",
       "2402    S_2   C_4      M  street_7   166.0    82.0  48.7       B"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.reindex(index=[1101,1203,1206,2402])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Height</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Average</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1101</th>\n",
       "      <td>173</td>\n",
       "      <td>M</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1102</th>\n",
       "      <td>192</td>\n",
       "      <td>F</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1103</th>\n",
       "      <td>186</td>\n",
       "      <td>M</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1104</th>\n",
       "      <td>167</td>\n",
       "      <td>F</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1105</th>\n",
       "      <td>159</td>\n",
       "      <td>F</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1201</th>\n",
       "      <td>188</td>\n",
       "      <td>M</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1202</th>\n",
       "      <td>176</td>\n",
       "      <td>F</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1203</th>\n",
       "      <td>160</td>\n",
       "      <td>M</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1204</th>\n",
       "      <td>162</td>\n",
       "      <td>F</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1205</th>\n",
       "      <td>167</td>\n",
       "      <td>F</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1301</th>\n",
       "      <td>161</td>\n",
       "      <td>M</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1302</th>\n",
       "      <td>175</td>\n",
       "      <td>F</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1303</th>\n",
       "      <td>188</td>\n",
       "      <td>M</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1304</th>\n",
       "      <td>195</td>\n",
       "      <td>M</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1305</th>\n",
       "      <td>187</td>\n",
       "      <td>F</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2101</th>\n",
       "      <td>174</td>\n",
       "      <td>M</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2102</th>\n",
       "      <td>161</td>\n",
       "      <td>F</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2103</th>\n",
       "      <td>157</td>\n",
       "      <td>M</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2104</th>\n",
       "      <td>159</td>\n",
       "      <td>F</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2105</th>\n",
       "      <td>170</td>\n",
       "      <td>M</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2201</th>\n",
       "      <td>193</td>\n",
       "      <td>M</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2202</th>\n",
       "      <td>194</td>\n",
       "      <td>F</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2203</th>\n",
       "      <td>155</td>\n",
       "      <td>M</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2204</th>\n",
       "      <td>175</td>\n",
       "      <td>M</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2205</th>\n",
       "      <td>183</td>\n",
       "      <td>F</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2301</th>\n",
       "      <td>157</td>\n",
       "      <td>F</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2302</th>\n",
       "      <td>171</td>\n",
       "      <td>M</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2303</th>\n",
       "      <td>190</td>\n",
       "      <td>F</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2304</th>\n",
       "      <td>164</td>\n",
       "      <td>F</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2305</th>\n",
       "      <td>187</td>\n",
       "      <td>M</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2401</th>\n",
       "      <td>192</td>\n",
       "      <td>F</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2402</th>\n",
       "      <td>166</td>\n",
       "      <td>M</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2403</th>\n",
       "      <td>158</td>\n",
       "      <td>F</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2404</th>\n",
       "      <td>160</td>\n",
       "      <td>F</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2405</th>\n",
       "      <td>193</td>\n",
       "      <td>F</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Height Gender  Average\n",
       "ID                          \n",
       "1101     173      M      NaN\n",
       "1102     192      F      NaN\n",
       "1103     186      M      NaN\n",
       "1104     167      F      NaN\n",
       "1105     159      F      NaN\n",
       "1201     188      M      NaN\n",
       "1202     176      F      NaN\n",
       "1203     160      M      NaN\n",
       "1204     162      F      NaN\n",
       "1205     167      F      NaN\n",
       "1301     161      M      NaN\n",
       "1302     175      F      NaN\n",
       "1303     188      M      NaN\n",
       "1304     195      M      NaN\n",
       "1305     187      F      NaN\n",
       "2101     174      M      NaN\n",
       "2102     161      F      NaN\n",
       "2103     157      M      NaN\n",
       "2104     159      F      NaN\n",
       "2105     170      M      NaN\n",
       "2201     193      M      NaN\n",
       "2202     194      F      NaN\n",
       "2203     155      M      NaN\n",
       "2204     175      M      NaN\n",
       "2205     183      F      NaN\n",
       "2301     157      F      NaN\n",
       "2302     171      M      NaN\n",
       "2303     190      F      NaN\n",
       "2304     164      F      NaN\n",
       "2305     187      M      NaN\n",
       "2401     192      F      NaN\n",
       "2402     166      M      NaN\n",
       "2403     158      F      NaN\n",
       "2404     160      F      NaN\n",
       "2405     193      F      NaN"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.reindex(columns=['Height','Gender','Average'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "在设置索引的时候可以选择填充方法  也可以使用reindex函数（index =）或columns等于什么"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>School</th>\n",
       "      <th>Class</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Address</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1101</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_1</td>\n",
       "      <td>173</td>\n",
       "      <td>63</td>\n",
       "      <td>34.0</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1203</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_6</td>\n",
       "      <td>160</td>\n",
       "      <td>53</td>\n",
       "      <td>58.8</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1206</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>161</td>\n",
       "      <td>68</td>\n",
       "      <td>31.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2402</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>166</td>\n",
       "      <td>82</td>\n",
       "      <td>48.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     School Class Gender   Address  Height  Weight  Math Physics\n",
       "ID                                                              \n",
       "1101    S_1   C_1      M  street_1     173      63  34.0      A+\n",
       "1203    S_1   C_2      M  street_6     160      53  58.8      A+\n",
       "1206    S_1   C_3      M  street_4     161      68  31.5      B+\n",
       "2402    S_2   C_4      M  street_7     166      82  48.7       B"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.reindex(index=[1101,1203,1206,2402],method='bfill')\n",
    "#bfill表示用所在索引1206的后一个有效行填充，ffill为前一个有效行，nearest是指最近\n",
    "#这几种填充方法都不是最好的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_temp = pd.DataFrame({'Weight':range(5),\n",
    "                        'Height':range(5),\n",
    "                        'ID':[1101,1104,1103,1106,1102]}).set_index('ID').sort_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>School</th>\n",
       "      <th>Class</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Address</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1101</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_1</td>\n",
       "      <td>173</td>\n",
       "      <td>63</td>\n",
       "      <td>34.0</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1102</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>192</td>\n",
       "      <td>73</td>\n",
       "      <td>32.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1103</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_2</td>\n",
       "      <td>186</td>\n",
       "      <td>82</td>\n",
       "      <td>87.2</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1104</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>167</td>\n",
       "      <td>81</td>\n",
       "      <td>80.4</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1105</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_4</td>\n",
       "      <td>159</td>\n",
       "      <td>64</td>\n",
       "      <td>84.8</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1201</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_5</td>\n",
       "      <td>188</td>\n",
       "      <td>68</td>\n",
       "      <td>97.0</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1202</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_4</td>\n",
       "      <td>176</td>\n",
       "      <td>94</td>\n",
       "      <td>63.5</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1203</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_6</td>\n",
       "      <td>160</td>\n",
       "      <td>53</td>\n",
       "      <td>58.8</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1204</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_5</td>\n",
       "      <td>162</td>\n",
       "      <td>63</td>\n",
       "      <td>33.8</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1205</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>167</td>\n",
       "      <td>63</td>\n",
       "      <td>68.4</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1301</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>161</td>\n",
       "      <td>68</td>\n",
       "      <td>31.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1302</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_1</td>\n",
       "      <td>175</td>\n",
       "      <td>57</td>\n",
       "      <td>87.7</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1303</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>188</td>\n",
       "      <td>82</td>\n",
       "      <td>49.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1304</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_2</td>\n",
       "      <td>195</td>\n",
       "      <td>70</td>\n",
       "      <td>85.2</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1305</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_5</td>\n",
       "      <td>187</td>\n",
       "      <td>69</td>\n",
       "      <td>61.7</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2101</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>174</td>\n",
       "      <td>84</td>\n",
       "      <td>83.3</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2102</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>161</td>\n",
       "      <td>61</td>\n",
       "      <td>50.6</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2103</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>157</td>\n",
       "      <td>61</td>\n",
       "      <td>52.5</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2104</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_5</td>\n",
       "      <td>159</td>\n",
       "      <td>97</td>\n",
       "      <td>72.2</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2105</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>170</td>\n",
       "      <td>81</td>\n",
       "      <td>34.2</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2201</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_5</td>\n",
       "      <td>193</td>\n",
       "      <td>100</td>\n",
       "      <td>39.1</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2202</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_7</td>\n",
       "      <td>194</td>\n",
       "      <td>77</td>\n",
       "      <td>68.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2203</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>155</td>\n",
       "      <td>91</td>\n",
       "      <td>73.8</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2204</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_1</td>\n",
       "      <td>175</td>\n",
       "      <td>74</td>\n",
       "      <td>47.2</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2205</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_7</td>\n",
       "      <td>183</td>\n",
       "      <td>76</td>\n",
       "      <td>85.4</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2301</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_4</td>\n",
       "      <td>157</td>\n",
       "      <td>78</td>\n",
       "      <td>72.3</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2302</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_5</td>\n",
       "      <td>171</td>\n",
       "      <td>88</td>\n",
       "      <td>32.7</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2303</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_7</td>\n",
       "      <td>190</td>\n",
       "      <td>99</td>\n",
       "      <td>65.9</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2304</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>164</td>\n",
       "      <td>81</td>\n",
       "      <td>95.5</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2305</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>187</td>\n",
       "      <td>73</td>\n",
       "      <td>48.9</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2401</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>192</td>\n",
       "      <td>62</td>\n",
       "      <td>45.3</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2402</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>166</td>\n",
       "      <td>82</td>\n",
       "      <td>48.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2403</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>158</td>\n",
       "      <td>60</td>\n",
       "      <td>59.7</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2404</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>160</td>\n",
       "      <td>84</td>\n",
       "      <td>67.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2405</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>193</td>\n",
       "      <td>54</td>\n",
       "      <td>47.6</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     School Class Gender   Address  Height  Weight  Math Physics\n",
       "ID                                                              \n",
       "1101    S_1   C_1      M  street_1     173      63  34.0      A+\n",
       "1102    S_1   C_1      F  street_2     192      73  32.5      B+\n",
       "1103    S_1   C_1      M  street_2     186      82  87.2      B+\n",
       "1104    S_1   C_1      F  street_2     167      81  80.4      B-\n",
       "1105    S_1   C_1      F  street_4     159      64  84.8      B+\n",
       "1201    S_1   C_2      M  street_5     188      68  97.0      A-\n",
       "1202    S_1   C_2      F  street_4     176      94  63.5      B-\n",
       "1203    S_1   C_2      M  street_6     160      53  58.8      A+\n",
       "1204    S_1   C_2      F  street_5     162      63  33.8       B\n",
       "1205    S_1   C_2      F  street_6     167      63  68.4      B-\n",
       "1301    S_1   C_3      M  street_4     161      68  31.5      B+\n",
       "1302    S_1   C_3      F  street_1     175      57  87.7      A-\n",
       "1303    S_1   C_3      M  street_7     188      82  49.7       B\n",
       "1304    S_1   C_3      M  street_2     195      70  85.2       A\n",
       "1305    S_1   C_3      F  street_5     187      69  61.7      B-\n",
       "2101    S_2   C_1      M  street_7     174      84  83.3       C\n",
       "2102    S_2   C_1      F  street_6     161      61  50.6      B+\n",
       "2103    S_2   C_1      M  street_4     157      61  52.5      B-\n",
       "2104    S_2   C_1      F  street_5     159      97  72.2      B+\n",
       "2105    S_2   C_1      M  street_4     170      81  34.2       A\n",
       "2201    S_2   C_2      M  street_5     193     100  39.1       B\n",
       "2202    S_2   C_2      F  street_7     194      77  68.5      B+\n",
       "2203    S_2   C_2      M  street_4     155      91  73.8      A+\n",
       "2204    S_2   C_2      M  street_1     175      74  47.2      B-\n",
       "2205    S_2   C_2      F  street_7     183      76  85.4       B\n",
       "2301    S_2   C_3      F  street_4     157      78  72.3      B+\n",
       "2302    S_2   C_3      M  street_5     171      88  32.7       A\n",
       "2303    S_2   C_3      F  street_7     190      99  65.9       C\n",
       "2304    S_2   C_3      F  street_6     164      81  95.5      A-\n",
       "2305    S_2   C_3      M  street_4     187      73  48.9       B\n",
       "2401    S_2   C_4      F  street_2     192      62  45.3       A\n",
       "2402    S_2   C_4      M  street_7     166      82  48.7       B\n",
       "2403    S_2   C_4      F  street_6     158      60  59.7      B+\n",
       "2404    S_2   C_4      F  street_2     160      84  67.7       B\n",
       "2405    S_2   C_4      F  street_6     193      54  47.6       B"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "使用与表长相同的列作为索引时"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>School</th>\n",
       "      <th>Class</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Address</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_1</td>\n",
       "      <td>173</td>\n",
       "      <td>63</td>\n",
       "      <td>34.0</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>192</td>\n",
       "      <td>73</td>\n",
       "      <td>32.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_2</td>\n",
       "      <td>186</td>\n",
       "      <td>82</td>\n",
       "      <td>87.2</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>167</td>\n",
       "      <td>81</td>\n",
       "      <td>80.4</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_4</td>\n",
       "      <td>159</td>\n",
       "      <td>64</td>\n",
       "      <td>84.8</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_5</td>\n",
       "      <td>188</td>\n",
       "      <td>68</td>\n",
       "      <td>97.0</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_4</td>\n",
       "      <td>176</td>\n",
       "      <td>94</td>\n",
       "      <td>63.5</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_6</td>\n",
       "      <td>160</td>\n",
       "      <td>53</td>\n",
       "      <td>58.8</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_5</td>\n",
       "      <td>162</td>\n",
       "      <td>63</td>\n",
       "      <td>33.8</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>167</td>\n",
       "      <td>63</td>\n",
       "      <td>68.4</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>161</td>\n",
       "      <td>68</td>\n",
       "      <td>31.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_1</td>\n",
       "      <td>175</td>\n",
       "      <td>57</td>\n",
       "      <td>87.7</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>188</td>\n",
       "      <td>82</td>\n",
       "      <td>49.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_2</td>\n",
       "      <td>195</td>\n",
       "      <td>70</td>\n",
       "      <td>85.2</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_5</td>\n",
       "      <td>187</td>\n",
       "      <td>69</td>\n",
       "      <td>61.7</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>174</td>\n",
       "      <td>84</td>\n",
       "      <td>83.3</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>161</td>\n",
       "      <td>61</td>\n",
       "      <td>50.6</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>157</td>\n",
       "      <td>61</td>\n",
       "      <td>52.5</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_5</td>\n",
       "      <td>159</td>\n",
       "      <td>97</td>\n",
       "      <td>72.2</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>170</td>\n",
       "      <td>81</td>\n",
       "      <td>34.2</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_5</td>\n",
       "      <td>193</td>\n",
       "      <td>100</td>\n",
       "      <td>39.1</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_7</td>\n",
       "      <td>194</td>\n",
       "      <td>77</td>\n",
       "      <td>68.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>155</td>\n",
       "      <td>91</td>\n",
       "      <td>73.8</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_1</td>\n",
       "      <td>175</td>\n",
       "      <td>74</td>\n",
       "      <td>47.2</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_7</td>\n",
       "      <td>183</td>\n",
       "      <td>76</td>\n",
       "      <td>85.4</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_4</td>\n",
       "      <td>157</td>\n",
       "      <td>78</td>\n",
       "      <td>72.3</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_5</td>\n",
       "      <td>171</td>\n",
       "      <td>88</td>\n",
       "      <td>32.7</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_7</td>\n",
       "      <td>190</td>\n",
       "      <td>99</td>\n",
       "      <td>65.9</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>164</td>\n",
       "      <td>81</td>\n",
       "      <td>95.5</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>187</td>\n",
       "      <td>73</td>\n",
       "      <td>48.9</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>192</td>\n",
       "      <td>62</td>\n",
       "      <td>45.3</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>166</td>\n",
       "      <td>82</td>\n",
       "      <td>48.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>158</td>\n",
       "      <td>60</td>\n",
       "      <td>59.7</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>160</td>\n",
       "      <td>84</td>\n",
       "      <td>67.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>193</td>\n",
       "      <td>54</td>\n",
       "      <td>47.6</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   School Class Gender   Address  Height  Weight  Math Physics\n",
       "0     S_1   C_1      M  street_1     173      63  34.0      A+\n",
       "1     S_1   C_1      F  street_2     192      73  32.5      B+\n",
       "2     S_1   C_1      M  street_2     186      82  87.2      B+\n",
       "3     S_1   C_1      F  street_2     167      81  80.4      B-\n",
       "4     S_1   C_1      F  street_4     159      64  84.8      B+\n",
       "5     S_1   C_2      M  street_5     188      68  97.0      A-\n",
       "6     S_1   C_2      F  street_4     176      94  63.5      B-\n",
       "7     S_1   C_2      M  street_6     160      53  58.8      A+\n",
       "8     S_1   C_2      F  street_5     162      63  33.8       B\n",
       "9     S_1   C_2      F  street_6     167      63  68.4      B-\n",
       "10    S_1   C_3      M  street_4     161      68  31.5      B+\n",
       "11    S_1   C_3      F  street_1     175      57  87.7      A-\n",
       "12    S_1   C_3      M  street_7     188      82  49.7       B\n",
       "13    S_1   C_3      M  street_2     195      70  85.2       A\n",
       "14    S_1   C_3      F  street_5     187      69  61.7      B-\n",
       "15    S_2   C_1      M  street_7     174      84  83.3       C\n",
       "16    S_2   C_1      F  street_6     161      61  50.6      B+\n",
       "17    S_2   C_1      M  street_4     157      61  52.5      B-\n",
       "18    S_2   C_1      F  street_5     159      97  72.2      B+\n",
       "19    S_2   C_1      M  street_4     170      81  34.2       A\n",
       "20    S_2   C_2      M  street_5     193     100  39.1       B\n",
       "21    S_2   C_2      F  street_7     194      77  68.5      B+\n",
       "22    S_2   C_2      M  street_4     155      91  73.8      A+\n",
       "23    S_2   C_2      M  street_1     175      74  47.2      B-\n",
       "24    S_2   C_2      F  street_7     183      76  85.4       B\n",
       "25    S_2   C_3      F  street_4     157      78  72.3      B+\n",
       "26    S_2   C_3      M  street_5     171      88  32.7       A\n",
       "27    S_2   C_3      F  street_7     190      99  65.9       C\n",
       "28    S_2   C_3      F  street_6     164      81  95.5      A-\n",
       "29    S_2   C_3      M  street_4     187      73  48.9       B\n",
       "30    S_2   C_4      F  street_2     192      62  45.3       A\n",
       "31    S_2   C_4      M  street_7     166      82  48.7       B\n",
       "32    S_2   C_4      F  street_6     158      60  59.7      B+\n",
       "33    S_2   C_4      F  street_2     160      84  67.7       B\n",
       "34    S_2   C_4      F  street_6     193      54  47.6       B"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.set_index(pd.Series(range(df.shape[0])))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "rename_axis是针对多级索引的方法，作用是修改某一层的索引名，而不是索引标签"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_temp.rename_axis(index={'Lower':'LowerLower'},columns={'Big':'BigBig'})"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "rename方法用于修改列或者行索引标签，而不是索引名："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_temp.rename(index={'A':'T'},columns={'e':'changed_e'}).head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "以下内容非常重要，内容为常用索引性函数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1：where函数 对不满足条件的行全部设置为NAN 第二个参数为填充值可以自己指定"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>School</th>\n",
       "      <th>Class</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Address</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1101</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_1</td>\n",
       "      <td>173.0</td>\n",
       "      <td>63.0</td>\n",
       "      <td>34.0</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1102</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1103</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_2</td>\n",
       "      <td>186.0</td>\n",
       "      <td>82.0</td>\n",
       "      <td>87.2</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1104</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1105</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     School Class Gender   Address  Height  Weight  Math Physics\n",
       "ID                                                              \n",
       "1101    S_1   C_1      M  street_1   173.0    63.0  34.0      A+\n",
       "1102    NaN   NaN    NaN       NaN     NaN     NaN   NaN     NaN\n",
       "1103    S_1   C_1      M  street_2   186.0    82.0  87.2      B+\n",
       "1104    NaN   NaN    NaN       NaN     NaN     NaN   NaN     NaN\n",
       "1105    NaN   NaN    NaN       NaN     NaN     NaN   NaN     NaN"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.where(df['Gender']=='M').head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>School</th>\n",
       "      <th>Class</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Address</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1101</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_1</td>\n",
       "      <td>173.000000</td>\n",
       "      <td>63.000000</td>\n",
       "      <td>34.000000</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1102</th>\n",
       "      <td>0.172301</td>\n",
       "      <td>0.630534</td>\n",
       "      <td>0.408111</td>\n",
       "      <td>0.941086</td>\n",
       "      <td>0.469201</td>\n",
       "      <td>0.093834</td>\n",
       "      <td>0.148874</td>\n",
       "      <td>0.401045</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1103</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_2</td>\n",
       "      <td>186.000000</td>\n",
       "      <td>82.000000</td>\n",
       "      <td>87.200000</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1104</th>\n",
       "      <td>0.295511</td>\n",
       "      <td>0.72317</td>\n",
       "      <td>0.077594</td>\n",
       "      <td>0.505336</td>\n",
       "      <td>0.533105</td>\n",
       "      <td>0.565982</td>\n",
       "      <td>0.192843</td>\n",
       "      <td>0.247244</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1105</th>\n",
       "      <td>0.155442</td>\n",
       "      <td>0.471737</td>\n",
       "      <td>0.9973</td>\n",
       "      <td>0.352573</td>\n",
       "      <td>0.984032</td>\n",
       "      <td>0.598593</td>\n",
       "      <td>0.137493</td>\n",
       "      <td>0.647175</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1201</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_5</td>\n",
       "      <td>188.000000</td>\n",
       "      <td>68.000000</td>\n",
       "      <td>97.000000</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1202</th>\n",
       "      <td>0.913938</td>\n",
       "      <td>0.680908</td>\n",
       "      <td>0.456922</td>\n",
       "      <td>0.473245</td>\n",
       "      <td>0.266639</td>\n",
       "      <td>0.956195</td>\n",
       "      <td>0.221016</td>\n",
       "      <td>0.431129</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1203</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_6</td>\n",
       "      <td>160.000000</td>\n",
       "      <td>53.000000</td>\n",
       "      <td>58.800000</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1204</th>\n",
       "      <td>0.611082</td>\n",
       "      <td>0.163639</td>\n",
       "      <td>0.826479</td>\n",
       "      <td>0.0102753</td>\n",
       "      <td>0.292728</td>\n",
       "      <td>0.095275</td>\n",
       "      <td>0.570173</td>\n",
       "      <td>0.584841</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1205</th>\n",
       "      <td>0.175225</td>\n",
       "      <td>0.642832</td>\n",
       "      <td>0.238784</td>\n",
       "      <td>0.064776</td>\n",
       "      <td>0.972346</td>\n",
       "      <td>0.130326</td>\n",
       "      <td>0.012344</td>\n",
       "      <td>0.746011</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1301</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>161.000000</td>\n",
       "      <td>68.000000</td>\n",
       "      <td>31.500000</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1302</th>\n",
       "      <td>0.819688</td>\n",
       "      <td>0.701691</td>\n",
       "      <td>0.32678</td>\n",
       "      <td>0.206708</td>\n",
       "      <td>0.438821</td>\n",
       "      <td>0.661123</td>\n",
       "      <td>0.029369</td>\n",
       "      <td>0.381235</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1303</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>188.000000</td>\n",
       "      <td>82.000000</td>\n",
       "      <td>49.700000</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1304</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_2</td>\n",
       "      <td>195.000000</td>\n",
       "      <td>70.000000</td>\n",
       "      <td>85.200000</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1305</th>\n",
       "      <td>0.955468</td>\n",
       "      <td>0.557789</td>\n",
       "      <td>0.376626</td>\n",
       "      <td>0.828114</td>\n",
       "      <td>0.526023</td>\n",
       "      <td>0.667342</td>\n",
       "      <td>0.065845</td>\n",
       "      <td>0.856446</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2101</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>174.000000</td>\n",
       "      <td>84.000000</td>\n",
       "      <td>83.300000</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2102</th>\n",
       "      <td>0.632451</td>\n",
       "      <td>0.871276</td>\n",
       "      <td>0.89101</td>\n",
       "      <td>0.458309</td>\n",
       "      <td>0.455933</td>\n",
       "      <td>0.008151</td>\n",
       "      <td>0.754274</td>\n",
       "      <td>0.740127</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2103</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>157.000000</td>\n",
       "      <td>61.000000</td>\n",
       "      <td>52.500000</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2104</th>\n",
       "      <td>0.754394</td>\n",
       "      <td>0.117138</td>\n",
       "      <td>0.787217</td>\n",
       "      <td>0.254592</td>\n",
       "      <td>0.414658</td>\n",
       "      <td>0.144933</td>\n",
       "      <td>0.661142</td>\n",
       "      <td>0.554721</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2105</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>170.000000</td>\n",
       "      <td>81.000000</td>\n",
       "      <td>34.200000</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2201</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_5</td>\n",
       "      <td>193.000000</td>\n",
       "      <td>100.000000</td>\n",
       "      <td>39.100000</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2202</th>\n",
       "      <td>0.449838</td>\n",
       "      <td>0.0152619</td>\n",
       "      <td>0.108534</td>\n",
       "      <td>0.870494</td>\n",
       "      <td>0.202626</td>\n",
       "      <td>0.684389</td>\n",
       "      <td>0.143939</td>\n",
       "      <td>0.0601077</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2203</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>155.000000</td>\n",
       "      <td>91.000000</td>\n",
       "      <td>73.800000</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2204</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_1</td>\n",
       "      <td>175.000000</td>\n",
       "      <td>74.000000</td>\n",
       "      <td>47.200000</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2205</th>\n",
       "      <td>0.743109</td>\n",
       "      <td>0.954674</td>\n",
       "      <td>0.595218</td>\n",
       "      <td>0.164955</td>\n",
       "      <td>0.438054</td>\n",
       "      <td>0.705088</td>\n",
       "      <td>0.364151</td>\n",
       "      <td>0.0542539</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2301</th>\n",
       "      <td>0.861588</td>\n",
       "      <td>0.659976</td>\n",
       "      <td>0.13433</td>\n",
       "      <td>0.360591</td>\n",
       "      <td>0.646759</td>\n",
       "      <td>0.915083</td>\n",
       "      <td>0.362262</td>\n",
       "      <td>0.814426</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2302</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_5</td>\n",
       "      <td>171.000000</td>\n",
       "      <td>88.000000</td>\n",
       "      <td>32.700000</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2303</th>\n",
       "      <td>0.48266</td>\n",
       "      <td>0.43192</td>\n",
       "      <td>0.357972</td>\n",
       "      <td>0.745704</td>\n",
       "      <td>0.768571</td>\n",
       "      <td>0.935355</td>\n",
       "      <td>0.799496</td>\n",
       "      <td>0.767272</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2304</th>\n",
       "      <td>0.908087</td>\n",
       "      <td>0.965775</td>\n",
       "      <td>0.481746</td>\n",
       "      <td>0.545452</td>\n",
       "      <td>0.303745</td>\n",
       "      <td>0.926954</td>\n",
       "      <td>0.670326</td>\n",
       "      <td>0.999103</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2305</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>187.000000</td>\n",
       "      <td>73.000000</td>\n",
       "      <td>48.900000</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2401</th>\n",
       "      <td>0.972034</td>\n",
       "      <td>0.0950082</td>\n",
       "      <td>0.308246</td>\n",
       "      <td>0.0546802</td>\n",
       "      <td>0.660136</td>\n",
       "      <td>0.258774</td>\n",
       "      <td>0.719252</td>\n",
       "      <td>0.512991</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2402</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>166.000000</td>\n",
       "      <td>82.000000</td>\n",
       "      <td>48.700000</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2403</th>\n",
       "      <td>0.168776</td>\n",
       "      <td>0.364956</td>\n",
       "      <td>0.111723</td>\n",
       "      <td>0.796326</td>\n",
       "      <td>0.048537</td>\n",
       "      <td>0.546979</td>\n",
       "      <td>0.616726</td>\n",
       "      <td>0.720586</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2404</th>\n",
       "      <td>0.0103376</td>\n",
       "      <td>0.261803</td>\n",
       "      <td>0.597226</td>\n",
       "      <td>0.505052</td>\n",
       "      <td>0.633636</td>\n",
       "      <td>0.295076</td>\n",
       "      <td>0.773208</td>\n",
       "      <td>0.797324</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2405</th>\n",
       "      <td>0.184979</td>\n",
       "      <td>0.425774</td>\n",
       "      <td>0.560833</td>\n",
       "      <td>0.824392</td>\n",
       "      <td>0.721085</td>\n",
       "      <td>0.605969</td>\n",
       "      <td>0.705102</td>\n",
       "      <td>0.996179</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         School      Class    Gender    Address      Height      Weight  \\\n",
       "ID                                                                        \n",
       "1101        S_1        C_1         M   street_1  173.000000   63.000000   \n",
       "1102   0.172301   0.630534  0.408111   0.941086    0.469201    0.093834   \n",
       "1103        S_1        C_1         M   street_2  186.000000   82.000000   \n",
       "1104   0.295511    0.72317  0.077594   0.505336    0.533105    0.565982   \n",
       "1105   0.155442   0.471737    0.9973   0.352573    0.984032    0.598593   \n",
       "1201        S_1        C_2         M   street_5  188.000000   68.000000   \n",
       "1202   0.913938   0.680908  0.456922   0.473245    0.266639    0.956195   \n",
       "1203        S_1        C_2         M   street_6  160.000000   53.000000   \n",
       "1204   0.611082   0.163639  0.826479  0.0102753    0.292728    0.095275   \n",
       "1205   0.175225   0.642832  0.238784   0.064776    0.972346    0.130326   \n",
       "1301        S_1        C_3         M   street_4  161.000000   68.000000   \n",
       "1302   0.819688   0.701691   0.32678   0.206708    0.438821    0.661123   \n",
       "1303        S_1        C_3         M   street_7  188.000000   82.000000   \n",
       "1304        S_1        C_3         M   street_2  195.000000   70.000000   \n",
       "1305   0.955468   0.557789  0.376626   0.828114    0.526023    0.667342   \n",
       "2101        S_2        C_1         M   street_7  174.000000   84.000000   \n",
       "2102   0.632451   0.871276   0.89101   0.458309    0.455933    0.008151   \n",
       "2103        S_2        C_1         M   street_4  157.000000   61.000000   \n",
       "2104   0.754394   0.117138  0.787217   0.254592    0.414658    0.144933   \n",
       "2105        S_2        C_1         M   street_4  170.000000   81.000000   \n",
       "2201        S_2        C_2         M   street_5  193.000000  100.000000   \n",
       "2202   0.449838  0.0152619  0.108534   0.870494    0.202626    0.684389   \n",
       "2203        S_2        C_2         M   street_4  155.000000   91.000000   \n",
       "2204        S_2        C_2         M   street_1  175.000000   74.000000   \n",
       "2205   0.743109   0.954674  0.595218   0.164955    0.438054    0.705088   \n",
       "2301   0.861588   0.659976   0.13433   0.360591    0.646759    0.915083   \n",
       "2302        S_2        C_3         M   street_5  171.000000   88.000000   \n",
       "2303    0.48266    0.43192  0.357972   0.745704    0.768571    0.935355   \n",
       "2304   0.908087   0.965775  0.481746   0.545452    0.303745    0.926954   \n",
       "2305        S_2        C_3         M   street_4  187.000000   73.000000   \n",
       "2401   0.972034  0.0950082  0.308246  0.0546802    0.660136    0.258774   \n",
       "2402        S_2        C_4         M   street_7  166.000000   82.000000   \n",
       "2403   0.168776   0.364956  0.111723   0.796326    0.048537    0.546979   \n",
       "2404  0.0103376   0.261803  0.597226   0.505052    0.633636    0.295076   \n",
       "2405   0.184979   0.425774  0.560833   0.824392    0.721085    0.605969   \n",
       "\n",
       "           Math    Physics  \n",
       "ID                          \n",
       "1101  34.000000         A+  \n",
       "1102   0.148874   0.401045  \n",
       "1103  87.200000         B+  \n",
       "1104   0.192843   0.247244  \n",
       "1105   0.137493   0.647175  \n",
       "1201  97.000000         A-  \n",
       "1202   0.221016   0.431129  \n",
       "1203  58.800000         A+  \n",
       "1204   0.570173   0.584841  \n",
       "1205   0.012344   0.746011  \n",
       "1301  31.500000         B+  \n",
       "1302   0.029369   0.381235  \n",
       "1303  49.700000          B  \n",
       "1304  85.200000          A  \n",
       "1305   0.065845   0.856446  \n",
       "2101  83.300000          C  \n",
       "2102   0.754274   0.740127  \n",
       "2103  52.500000         B-  \n",
       "2104   0.661142   0.554721  \n",
       "2105  34.200000          A  \n",
       "2201  39.100000          B  \n",
       "2202   0.143939  0.0601077  \n",
       "2203  73.800000         A+  \n",
       "2204  47.200000         B-  \n",
       "2205   0.364151  0.0542539  \n",
       "2301   0.362262   0.814426  \n",
       "2302  32.700000          A  \n",
       "2303   0.799496   0.767272  \n",
       "2304   0.670326   0.999103  \n",
       "2305  48.900000          B  \n",
       "2401   0.719252   0.512991  \n",
       "2402  48.700000          B  \n",
       "2403   0.616726   0.720586  \n",
       "2404   0.773208   0.797324  \n",
       "2405   0.705102   0.996179  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.where(df['Gender']=='M',np.random.rand(df.shape[0],df.shape[1]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2：mask函数与where功能上完全相反 对值为TRUE的进行填充 实际用处应该不大"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3：query函数可以同时多个选择"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>School</th>\n",
       "      <th>Class</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Address</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1303</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>188</td>\n",
       "      <td>82</td>\n",
       "      <td>49.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2304</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>164</td>\n",
       "      <td>81</td>\n",
       "      <td>95.5</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2402</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>166</td>\n",
       "      <td>82</td>\n",
       "      <td>48.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     School Class Gender   Address  Height  Weight  Math Physics\n",
       "ID                                                              \n",
       "1303    S_1   C_3      M  street_7     188      82  49.7       B\n",
       "2304    S_2   C_3      F  street_6     164      81  95.5      A-\n",
       "2402    S_2   C_4      M  street_7     166      82  48.7       B"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.query('(Address in [\"street_6\",\"street_7\"])&(Weight>(70+10))&(ID in [1303,2304,2402])')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>School</th>\n",
       "      <th>Class</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Address</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1101</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_1</td>\n",
       "      <td>173</td>\n",
       "      <td>63</td>\n",
       "      <td>34.0</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1102</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>192</td>\n",
       "      <td>73</td>\n",
       "      <td>32.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1103</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_2</td>\n",
       "      <td>186</td>\n",
       "      <td>82</td>\n",
       "      <td>87.2</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1104</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>167</td>\n",
       "      <td>81</td>\n",
       "      <td>80.4</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1105</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_4</td>\n",
       "      <td>159</td>\n",
       "      <td>64</td>\n",
       "      <td>84.8</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1201</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_5</td>\n",
       "      <td>188</td>\n",
       "      <td>68</td>\n",
       "      <td>97.0</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1202</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_4</td>\n",
       "      <td>176</td>\n",
       "      <td>94</td>\n",
       "      <td>63.5</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1203</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_6</td>\n",
       "      <td>160</td>\n",
       "      <td>53</td>\n",
       "      <td>58.8</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1204</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_5</td>\n",
       "      <td>162</td>\n",
       "      <td>63</td>\n",
       "      <td>33.8</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1205</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>167</td>\n",
       "      <td>63</td>\n",
       "      <td>68.4</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1301</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>161</td>\n",
       "      <td>68</td>\n",
       "      <td>31.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1302</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_1</td>\n",
       "      <td>175</td>\n",
       "      <td>57</td>\n",
       "      <td>87.7</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1303</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>188</td>\n",
       "      <td>82</td>\n",
       "      <td>49.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1304</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_2</td>\n",
       "      <td>195</td>\n",
       "      <td>70</td>\n",
       "      <td>85.2</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1305</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_5</td>\n",
       "      <td>187</td>\n",
       "      <td>69</td>\n",
       "      <td>61.7</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2101</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>174</td>\n",
       "      <td>84</td>\n",
       "      <td>83.3</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2102</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>161</td>\n",
       "      <td>61</td>\n",
       "      <td>50.6</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2103</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>157</td>\n",
       "      <td>61</td>\n",
       "      <td>52.5</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2104</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>F</td>\n",
       "      <td>street_5</td>\n",
       "      <td>159</td>\n",
       "      <td>97</td>\n",
       "      <td>72.2</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2105</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>170</td>\n",
       "      <td>81</td>\n",
       "      <td>34.2</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2201</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_5</td>\n",
       "      <td>193</td>\n",
       "      <td>100</td>\n",
       "      <td>39.1</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2202</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_7</td>\n",
       "      <td>194</td>\n",
       "      <td>77</td>\n",
       "      <td>68.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2203</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>155</td>\n",
       "      <td>91</td>\n",
       "      <td>73.8</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2204</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_1</td>\n",
       "      <td>175</td>\n",
       "      <td>74</td>\n",
       "      <td>47.2</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2205</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_7</td>\n",
       "      <td>183</td>\n",
       "      <td>76</td>\n",
       "      <td>85.4</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2301</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_4</td>\n",
       "      <td>157</td>\n",
       "      <td>78</td>\n",
       "      <td>72.3</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2302</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_5</td>\n",
       "      <td>171</td>\n",
       "      <td>88</td>\n",
       "      <td>32.7</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2303</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_7</td>\n",
       "      <td>190</td>\n",
       "      <td>99</td>\n",
       "      <td>65.9</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2304</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>164</td>\n",
       "      <td>81</td>\n",
       "      <td>95.5</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2305</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>187</td>\n",
       "      <td>73</td>\n",
       "      <td>48.9</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2401</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>192</td>\n",
       "      <td>62</td>\n",
       "      <td>45.3</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2402</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>166</td>\n",
       "      <td>82</td>\n",
       "      <td>48.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2403</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>158</td>\n",
       "      <td>60</td>\n",
       "      <td>59.7</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2404</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>160</td>\n",
       "      <td>84</td>\n",
       "      <td>67.7</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2405</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>193</td>\n",
       "      <td>54</td>\n",
       "      <td>47.6</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     School Class Gender   Address  Height  Weight  Math Physics\n",
       "ID                                                              \n",
       "1101    S_1   C_1      M  street_1     173      63  34.0      A+\n",
       "1102    S_1   C_1      F  street_2     192      73  32.5      B+\n",
       "1103    S_1   C_1      M  street_2     186      82  87.2      B+\n",
       "1104    S_1   C_1      F  street_2     167      81  80.4      B-\n",
       "1105    S_1   C_1      F  street_4     159      64  84.8      B+\n",
       "1201    S_1   C_2      M  street_5     188      68  97.0      A-\n",
       "1202    S_1   C_2      F  street_4     176      94  63.5      B-\n",
       "1203    S_1   C_2      M  street_6     160      53  58.8      A+\n",
       "1204    S_1   C_2      F  street_5     162      63  33.8       B\n",
       "1205    S_1   C_2      F  street_6     167      63  68.4      B-\n",
       "1301    S_1   C_3      M  street_4     161      68  31.5      B+\n",
       "1302    S_1   C_3      F  street_1     175      57  87.7      A-\n",
       "1303    S_1   C_3      M  street_7     188      82  49.7       B\n",
       "1304    S_1   C_3      M  street_2     195      70  85.2       A\n",
       "1305    S_1   C_3      F  street_5     187      69  61.7      B-\n",
       "2101    S_2   C_1      M  street_7     174      84  83.3       C\n",
       "2102    S_2   C_1      F  street_6     161      61  50.6      B+\n",
       "2103    S_2   C_1      M  street_4     157      61  52.5      B-\n",
       "2104    S_2   C_1      F  street_5     159      97  72.2      B+\n",
       "2105    S_2   C_1      M  street_4     170      81  34.2       A\n",
       "2201    S_2   C_2      M  street_5     193     100  39.1       B\n",
       "2202    S_2   C_2      F  street_7     194      77  68.5      B+\n",
       "2203    S_2   C_2      M  street_4     155      91  73.8      A+\n",
       "2204    S_2   C_2      M  street_1     175      74  47.2      B-\n",
       "2205    S_2   C_2      F  street_7     183      76  85.4       B\n",
       "2301    S_2   C_3      F  street_4     157      78  72.3      B+\n",
       "2302    S_2   C_3      M  street_5     171      88  32.7       A\n",
       "2303    S_2   C_3      F  street_7     190      99  65.9       C\n",
       "2304    S_2   C_3      F  street_6     164      81  95.5      A-\n",
       "2305    S_2   C_3      M  street_4     187      73  48.9       B\n",
       "2401    S_2   C_4      F  street_2     192      62  45.3       A\n",
       "2402    S_2   C_4      M  street_7     166      82  48.7       B\n",
       "2403    S_2   C_4      F  street_6     158      60  59.7      B+\n",
       "2404    S_2   C_4      F  street_2     160      84  67.7       B\n",
       "2405    S_2   C_4      F  street_6     193      54  47.6       B"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "重复元素的处理\n",
    "1：使用duplicated方法\n",
    "可选参数keep默认为first，即首次出现设为不重复，若为last，则最后一次设为不重复，若为False，则所有重复项为False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ID\n",
       "1101    False\n",
       "1102     True\n",
       "1103     True\n",
       "1104     True\n",
       "1105     True\n",
       "1201    False\n",
       "1202     True\n",
       "1203     True\n",
       "1204     True\n",
       "1205     True\n",
       "1301    False\n",
       "1302     True\n",
       "1303     True\n",
       "1304     True\n",
       "1305     True\n",
       "2101     True\n",
       "2102     True\n",
       "2103     True\n",
       "2104     True\n",
       "2105     True\n",
       "2201     True\n",
       "2202     True\n",
       "2203     True\n",
       "2204     True\n",
       "2205     True\n",
       "2301     True\n",
       "2302     True\n",
       "2303     True\n",
       "2304     True\n",
       "2305     True\n",
       "2401    False\n",
       "2402     True\n",
       "2403     True\n",
       "2404     True\n",
       "2405     True\n",
       "dtype: bool"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.duplicated('Class')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.drop_duplicates 删除重复项仅保留一个\n",
    "传入多列的时候将多列共同视为一个多级索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>School</th>\n",
       "      <th>Class</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Address</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1101</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_1</td>\n",
       "      <td>173</td>\n",
       "      <td>63</td>\n",
       "      <td>34.0</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1201</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_5</td>\n",
       "      <td>188</td>\n",
       "      <td>68</td>\n",
       "      <td>97.0</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1301</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>161</td>\n",
       "      <td>68</td>\n",
       "      <td>31.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2401</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>192</td>\n",
       "      <td>62</td>\n",
       "      <td>45.3</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     School Class Gender   Address  Height  Weight  Math Physics\n",
       "ID                                                              \n",
       "1101    S_1   C_1      M  street_1     173      63  34.0      A+\n",
       "1201    S_1   C_2      M  street_5     188      68  97.0      A-\n",
       "1301    S_1   C_3      M  street_4     161      68  31.5      B+\n",
       "2401    S_2   C_4      F  street_2     192      62  45.3       A"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.drop_duplicates('Class')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>School</th>\n",
       "      <th>Class</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Address</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1101</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_1</td>\n",
       "      <td>173</td>\n",
       "      <td>63</td>\n",
       "      <td>34.0</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1201</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_5</td>\n",
       "      <td>188</td>\n",
       "      <td>68</td>\n",
       "      <td>97.0</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1301</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_4</td>\n",
       "      <td>161</td>\n",
       "      <td>68</td>\n",
       "      <td>31.5</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2101</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_1</td>\n",
       "      <td>M</td>\n",
       "      <td>street_7</td>\n",
       "      <td>174</td>\n",
       "      <td>84</td>\n",
       "      <td>83.3</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2201</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_5</td>\n",
       "      <td>193</td>\n",
       "      <td>100</td>\n",
       "      <td>39.1</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2301</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_4</td>\n",
       "      <td>157</td>\n",
       "      <td>78</td>\n",
       "      <td>72.3</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2401</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>F</td>\n",
       "      <td>street_2</td>\n",
       "      <td>192</td>\n",
       "      <td>62</td>\n",
       "      <td>45.3</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     School Class Gender   Address  Height  Weight  Math Physics\n",
       "ID                                                              \n",
       "1101    S_1   C_1      M  street_1     173      63  34.0      A+\n",
       "1201    S_1   C_2      M  street_5     188      68  97.0      A-\n",
       "1301    S_1   C_3      M  street_4     161      68  31.5      B+\n",
       "2101    S_2   C_1      M  street_7     174      84  83.3       C\n",
       "2201    S_2   C_2      M  street_5     193     100  39.1       B\n",
       "2301    S_2   C_3      F  street_4     157      78  72.3      B+\n",
       "2401    S_2   C_4      F  street_2     192      62  45.3       A"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.drop_duplicates(['School','Class'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " 抽样函数sample  \n",
    " frac为抽样比 \n",
    " replace为是否放回抽样 \n",
    " axis为抽样维度\n",
    " weights为样本权重，自动归一化，可以使某一列为权重"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>School</th>\n",
       "      <th>Class</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Address</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1302</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_1</td>\n",
       "      <td>175</td>\n",
       "      <td>57</td>\n",
       "      <td>87.7</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1203</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_2</td>\n",
       "      <td>M</td>\n",
       "      <td>street_6</td>\n",
       "      <td>160</td>\n",
       "      <td>53</td>\n",
       "      <td>58.8</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2403</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_4</td>\n",
       "      <td>F</td>\n",
       "      <td>street_6</td>\n",
       "      <td>158</td>\n",
       "      <td>60</td>\n",
       "      <td>59.7</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2303</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_7</td>\n",
       "      <td>190</td>\n",
       "      <td>99</td>\n",
       "      <td>65.9</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2205</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_7</td>\n",
       "      <td>183</td>\n",
       "      <td>76</td>\n",
       "      <td>85.4</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     School Class Gender   Address  Height  Weight  Math Physics\n",
       "ID                                                              \n",
       "1302    S_1   C_3      F  street_1     175      57  87.7      A-\n",
       "1203    S_1   C_2      M  street_6     160      53  58.8      A+\n",
       "2403    S_2   C_4      F  street_6     158      60  59.7      B+\n",
       "2303    S_2   C_3      F  street_7     190      99  65.9       C\n",
       "2205    S_2   C_2      F  street_7     183      76  85.4       B"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.sample(n=5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>School</th>\n",
       "      <th>Class</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Address</th>\n",
       "      <th>Height</th>\n",
       "      <th>Weight</th>\n",
       "      <th>Math</th>\n",
       "      <th>Physics</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2302</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_3</td>\n",
       "      <td>M</td>\n",
       "      <td>street_5</td>\n",
       "      <td>171</td>\n",
       "      <td>88</td>\n",
       "      <td>32.7</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1302</th>\n",
       "      <td>S_1</td>\n",
       "      <td>C_3</td>\n",
       "      <td>F</td>\n",
       "      <td>street_1</td>\n",
       "      <td>175</td>\n",
       "      <td>57</td>\n",
       "      <td>87.7</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2205</th>\n",
       "      <td>S_2</td>\n",
       "      <td>C_2</td>\n",
       "      <td>F</td>\n",
       "      <td>street_7</td>\n",
       "      <td>183</td>\n",
       "      <td>76</td>\n",
       "      <td>85.4</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     School Class Gender   Address  Height  Weight  Math Physics\n",
       "ID                                                              \n",
       "2302    S_2   C_3      M  street_5     171      88  32.7       A\n",
       "1302    S_1   C_3      F  street_1     175      57  87.7      A-\n",
       "2205    S_2   C_2      F  street_7     183      76  85.4       B"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.sample(n=3,weights=df['Height']).head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "练习一"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<bound method NDFrame.head of                datetime      shape  duration (seconds)   latitude   longitude\n",
       "0      10/10/1949 20:30   cylinder              2700.0  29.883056  -97.941111\n",
       "1      10/10/1949 21:00      light              7200.0  29.384210  -98.581082\n",
       "2      10/10/1955 17:00     circle                20.0  53.200000   -2.916667\n",
       "3      10/10/1956 21:00     circle                20.0  28.978333  -96.645833\n",
       "4      10/10/1960 20:00      light               900.0  21.418056 -157.803611\n",
       "5      10/10/1961 19:00     sphere               300.0  36.595000  -82.188889\n",
       "6      10/10/1965 21:00     circle               180.0  51.434722   -3.180000\n",
       "7      10/10/1965 23:45       disk              1200.0  41.117500  -73.408333\n",
       "8      10/10/1966 20:00       disk               180.0  33.586111  -86.286111\n",
       "9      10/10/1966 21:00       disk               120.0  30.294722  -82.984167\n",
       "10     10/10/1968 13:00     circle               300.0  33.916389 -118.351667\n",
       "11     10/10/1968 19:00   fireball               180.0  35.233333  -82.734444\n",
       "12     10/10/1970 16:00       disk              1800.0  40.668611  -73.527500\n",
       "13     10/10/1970 19:00    unknown               180.0  37.153611  -83.761944\n",
       "14     10/10/1971 21:00       oval                30.0  35.823889  -80.253611\n",
       "15     10/10/1972 19:00     circle              1200.0  36.843056  -83.321944\n",
       "16     10/10/1972 22:30       disk               120.0  42.537778  -83.233056\n",
       "17     10/10/1973 19:00       disk              1800.0  41.325278  -72.193611\n",
       "18     10/10/1973 23:00      light                20.0  32.364167  -64.678611\n",
       "19     10/10/1974 19:30      other              2700.0  42.391667  -71.566667\n",
       "20     10/10/1974 21:30       disk              1200.0  51.500000   -3.200000\n",
       "21     10/10/1974 23:00      light              1200.0  38.105556  -98.659722\n",
       "22     10/10/1975 17:00      light               360.0  32.854444  -79.975000\n",
       "23     10/10/1976 20:30       oval                60.0  45.582778 -122.352222\n",
       "24     10/10/1976 22:00      cigar                 3.0  51.783333   -0.783333\n",
       "25     10/10/1977 12:00      other                30.0  29.423889  -98.493333\n",
       "26     10/10/1977 22:00      light                30.0  38.254167  -85.759444\n",
       "27     10/10/1978 02:00  rectangle               300.0  40.700833  -73.713333\n",
       "28     10/10/1979 00:00    chevron               900.0  41.700278  -73.921389\n",
       "29     10/10/1979 22:00   triangle               270.0  53.970571 -111.689885\n",
       "...                 ...        ...                 ...        ...         ...\n",
       "80302    9/9/2012 20:00      light             10800.0  35.721111  -77.915833\n",
       "80303    9/9/2012 20:10     circle               600.0  40.700833  -73.713333\n",
       "80304    9/9/2012 20:30      light               120.0  36.200000  -86.518611\n",
       "80305    9/9/2012 20:30    chevron               900.0  34.278333 -119.292222\n",
       "80306    9/9/2012 20:52     circle                10.0  40.562222 -111.928889\n",
       "80307    9/9/2012 21:00       oval               600.0  41.681944  -85.976667\n",
       "80308    9/9/2012 21:00      light              1290.0  40.714167  -74.006389\n",
       "80309    9/9/2012 21:00       oval                60.0  33.433056  -79.121667\n",
       "80310    9/9/2012 21:00     circle               300.0  34.278333 -119.292222\n",
       "80311    9/9/2012 21:55      flash               900.0  32.776389  -79.931111\n",
       "80312    9/9/2012 23:00      light                 5.0  34.297778  -83.824167\n",
       "80313    9/9/2013 00:15    unknown                 1.0  36.846667  -76.285556\n",
       "80314    9/9/2013 01:50   triangle               180.0  42.886389  -78.878611\n",
       "80315    9/9/2013 03:00    unknown               120.0  41.052500  -80.608056\n",
       "80316    9/9/2013 09:51      light                 4.0  32.715278 -117.156389\n",
       "80317    9/9/2013 12:34      cigar                 8.0  30.505000  -97.820000\n",
       "80318    9/9/2013 13:10    unknown                90.0  53.250000 -113.783333\n",
       "80319    9/9/2013 20:15      other              3600.0  40.858433  -74.163755\n",
       "80320    9/9/2013 20:20   fireball                60.0  33.209722  -87.569167\n",
       "80321    9/9/2013 20:21   fireball                 3.0  36.529722  -87.359444\n",
       "80322    9/9/2013 21:00      light                15.0  50.465843   22.891814\n",
       "80323    9/9/2013 21:00   triangle                60.0  29.651389  -82.325000\n",
       "80324    9/9/2013 21:00      light               120.0  34.367594  -77.710548\n",
       "80325    9/9/2013 21:00   fireball               180.0  46.300000  -63.216667\n",
       "80326    9/9/2013 21:00     sphere                20.0  34.101389  -84.519444\n",
       "80327    9/9/2013 21:15      light               600.0  36.165833  -86.784444\n",
       "80328    9/9/2013 22:00     circle              1200.0  43.613611 -116.202500\n",
       "80329    9/9/2013 22:00      other              1200.0  38.297222 -122.284444\n",
       "80330    9/9/2013 22:20     circle                 5.0  38.901111  -77.265556\n",
       "80331    9/9/2013 23:00      cigar              1020.0  35.652778  -97.477778\n",
       "\n",
       "[80332 rows x 5 columns]>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = pd.read_csv('data/UFO.csv')\n",
    "data.head"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "在所有被观测时间超过60s的时间中，哪个形状最多"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "light        10713\n",
       "triangle      4999\n",
       "circle        4964\n",
       "unknown       3594\n",
       "disk          3579\n",
       "other         3527\n",
       "sphere        3435\n",
       "fireball      3356\n",
       "oval          2348\n",
       "formation     1618\n",
       "changing      1576\n",
       "cigar         1264\n",
       "diamond        837\n",
       "cylinder       833\n",
       "rectangle      790\n",
       "flash          554\n",
       "egg            471\n",
       "chevron        467\n",
       "teardrop       431\n",
       "cone           219\n",
       "cross          164\n",
       "delta            4\n",
       "hexagon          1\n",
       "changed          1\n",
       "crescent         1\n",
       "pyramid          1\n",
       "round            1\n",
       "Name: shape, dtype: int64"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#解题方式一\n",
    "data.where(data['duration (seconds)']>60).dropna()['shape'].value_counts().index[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "light        10713\n",
       "triangle      4999\n",
       "circle        4964\n",
       "unknown       3594\n",
       "disk          3579\n",
       "other         3527\n",
       "sphere        3435\n",
       "fireball      3356\n",
       "oval          2348\n",
       "formation     1618\n",
       "changing      1576\n",
       "cigar         1264\n",
       "diamond        837\n",
       "cylinder       833\n",
       "rectangle      790\n",
       "flash          554\n",
       "egg            471\n",
       "chevron        467\n",
       "teardrop       431\n",
       "cone           219\n",
       "cross          164\n",
       "delta            4\n",
       "hexagon          1\n",
       "changed          1\n",
       "crescent         1\n",
       "pyramid          1\n",
       "round            1\n",
       "Name: shape, dtype: int64"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#解题方式二\n",
    "data.rename(columns = {\"duration (seconds)\":\"duration\"},inplace =True)\n",
    "data.query('duration>60')['shape'].value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "对经纬度进行划分：-180°至180°以30°为一个划分，-90°至90°以18°为一个划分，请问哪个区域中报告的UFO事件数量最多？\n",
    "latitude 纬度 longitude经度\n",
    "pd.cut函数是用来将连续值进行分段的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "data['long']= pd.cut(data['longitude'],bins=np.linspace(-180,180,13).tolist())\n",
    "data['lat'] = pd.cut(data['latitude'],bins=np.linspace(-90,90,11).tolist())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>datetime</th>\n",
       "      <th>shape</th>\n",
       "      <th>duration</th>\n",
       "      <th>latitude</th>\n",
       "      <th>longitude</th>\n",
       "      <th>long</th>\n",
       "      <th>lat</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10/10/1949 20:30</td>\n",
       "      <td>cylinder</td>\n",
       "      <td>2700.0</td>\n",
       "      <td>29.883056</td>\n",
       "      <td>-97.941111</td>\n",
       "      <td>(-120.0, -90.0]</td>\n",
       "      <td>(18.0, 36.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10/10/1949 21:00</td>\n",
       "      <td>light</td>\n",
       "      <td>7200.0</td>\n",
       "      <td>29.384210</td>\n",
       "      <td>-98.581082</td>\n",
       "      <td>(-120.0, -90.0]</td>\n",
       "      <td>(18.0, 36.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10/10/1955 17:00</td>\n",
       "      <td>circle</td>\n",
       "      <td>20.0</td>\n",
       "      <td>53.200000</td>\n",
       "      <td>-2.916667</td>\n",
       "      <td>(-30.0, 0.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>10/10/1956 21:00</td>\n",
       "      <td>circle</td>\n",
       "      <td>20.0</td>\n",
       "      <td>28.978333</td>\n",
       "      <td>-96.645833</td>\n",
       "      <td>(-120.0, -90.0]</td>\n",
       "      <td>(18.0, 36.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>10/10/1960 20:00</td>\n",
       "      <td>light</td>\n",
       "      <td>900.0</td>\n",
       "      <td>21.418056</td>\n",
       "      <td>-157.803611</td>\n",
       "      <td>(-180.0, -150.0]</td>\n",
       "      <td>(18.0, 36.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>10/10/1961 19:00</td>\n",
       "      <td>sphere</td>\n",
       "      <td>300.0</td>\n",
       "      <td>36.595000</td>\n",
       "      <td>-82.188889</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>10/10/1965 21:00</td>\n",
       "      <td>circle</td>\n",
       "      <td>180.0</td>\n",
       "      <td>51.434722</td>\n",
       "      <td>-3.180000</td>\n",
       "      <td>(-30.0, 0.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>10/10/1965 23:45</td>\n",
       "      <td>disk</td>\n",
       "      <td>1200.0</td>\n",
       "      <td>41.117500</td>\n",
       "      <td>-73.408333</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>10/10/1966 20:00</td>\n",
       "      <td>disk</td>\n",
       "      <td>180.0</td>\n",
       "      <td>33.586111</td>\n",
       "      <td>-86.286111</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(18.0, 36.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10/10/1966 21:00</td>\n",
       "      <td>disk</td>\n",
       "      <td>120.0</td>\n",
       "      <td>30.294722</td>\n",
       "      <td>-82.984167</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(18.0, 36.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>10/10/1968 13:00</td>\n",
       "      <td>circle</td>\n",
       "      <td>300.0</td>\n",
       "      <td>33.916389</td>\n",
       "      <td>-118.351667</td>\n",
       "      <td>(-120.0, -90.0]</td>\n",
       "      <td>(18.0, 36.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>10/10/1968 19:00</td>\n",
       "      <td>fireball</td>\n",
       "      <td>180.0</td>\n",
       "      <td>35.233333</td>\n",
       "      <td>-82.734444</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(18.0, 36.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>10/10/1970 16:00</td>\n",
       "      <td>disk</td>\n",
       "      <td>1800.0</td>\n",
       "      <td>40.668611</td>\n",
       "      <td>-73.527500</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>10/10/1970 19:00</td>\n",
       "      <td>unknown</td>\n",
       "      <td>180.0</td>\n",
       "      <td>37.153611</td>\n",
       "      <td>-83.761944</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>10/10/1971 21:00</td>\n",
       "      <td>oval</td>\n",
       "      <td>30.0</td>\n",
       "      <td>35.823889</td>\n",
       "      <td>-80.253611</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(18.0, 36.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>10/10/1972 19:00</td>\n",
       "      <td>circle</td>\n",
       "      <td>1200.0</td>\n",
       "      <td>36.843056</td>\n",
       "      <td>-83.321944</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>10/10/1972 22:30</td>\n",
       "      <td>disk</td>\n",
       "      <td>120.0</td>\n",
       "      <td>42.537778</td>\n",
       "      <td>-83.233056</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>10/10/1973 19:00</td>\n",
       "      <td>disk</td>\n",
       "      <td>1800.0</td>\n",
       "      <td>41.325278</td>\n",
       "      <td>-72.193611</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>10/10/1973 23:00</td>\n",
       "      <td>light</td>\n",
       "      <td>20.0</td>\n",
       "      <td>32.364167</td>\n",
       "      <td>-64.678611</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(18.0, 36.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>10/10/1974 19:30</td>\n",
       "      <td>other</td>\n",
       "      <td>2700.0</td>\n",
       "      <td>42.391667</td>\n",
       "      <td>-71.566667</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>10/10/1974 21:30</td>\n",
       "      <td>disk</td>\n",
       "      <td>1200.0</td>\n",
       "      <td>51.500000</td>\n",
       "      <td>-3.200000</td>\n",
       "      <td>(-30.0, 0.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>10/10/1974 23:00</td>\n",
       "      <td>light</td>\n",
       "      <td>1200.0</td>\n",
       "      <td>38.105556</td>\n",
       "      <td>-98.659722</td>\n",
       "      <td>(-120.0, -90.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>10/10/1975 17:00</td>\n",
       "      <td>light</td>\n",
       "      <td>360.0</td>\n",
       "      <td>32.854444</td>\n",
       "      <td>-79.975000</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(18.0, 36.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>10/10/1976 20:30</td>\n",
       "      <td>oval</td>\n",
       "      <td>60.0</td>\n",
       "      <td>45.582778</td>\n",
       "      <td>-122.352222</td>\n",
       "      <td>(-150.0, -120.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>10/10/1976 22:00</td>\n",
       "      <td>cigar</td>\n",
       "      <td>3.0</td>\n",
       "      <td>51.783333</td>\n",
       "      <td>-0.783333</td>\n",
       "      <td>(-30.0, 0.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>10/10/1977 12:00</td>\n",
       "      <td>other</td>\n",
       "      <td>30.0</td>\n",
       "      <td>29.423889</td>\n",
       "      <td>-98.493333</td>\n",
       "      <td>(-120.0, -90.0]</td>\n",
       "      <td>(18.0, 36.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>10/10/1977 22:00</td>\n",
       "      <td>light</td>\n",
       "      <td>30.0</td>\n",
       "      <td>38.254167</td>\n",
       "      <td>-85.759444</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>10/10/1978 02:00</td>\n",
       "      <td>rectangle</td>\n",
       "      <td>300.0</td>\n",
       "      <td>40.700833</td>\n",
       "      <td>-73.713333</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>10/10/1979 00:00</td>\n",
       "      <td>chevron</td>\n",
       "      <td>900.0</td>\n",
       "      <td>41.700278</td>\n",
       "      <td>-73.921389</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>10/10/1979 22:00</td>\n",
       "      <td>triangle</td>\n",
       "      <td>270.0</td>\n",
       "      <td>53.970571</td>\n",
       "      <td>-111.689885</td>\n",
       "      <td>(-120.0, -90.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80302</th>\n",
       "      <td>9/9/2012 20:00</td>\n",
       "      <td>light</td>\n",
       "      <td>10800.0</td>\n",
       "      <td>35.721111</td>\n",
       "      <td>-77.915833</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(18.0, 36.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80303</th>\n",
       "      <td>9/9/2012 20:10</td>\n",
       "      <td>circle</td>\n",
       "      <td>600.0</td>\n",
       "      <td>40.700833</td>\n",
       "      <td>-73.713333</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80304</th>\n",
       "      <td>9/9/2012 20:30</td>\n",
       "      <td>light</td>\n",
       "      <td>120.0</td>\n",
       "      <td>36.200000</td>\n",
       "      <td>-86.518611</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80305</th>\n",
       "      <td>9/9/2012 20:30</td>\n",
       "      <td>chevron</td>\n",
       "      <td>900.0</td>\n",
       "      <td>34.278333</td>\n",
       "      <td>-119.292222</td>\n",
       "      <td>(-120.0, -90.0]</td>\n",
       "      <td>(18.0, 36.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80306</th>\n",
       "      <td>9/9/2012 20:52</td>\n",
       "      <td>circle</td>\n",
       "      <td>10.0</td>\n",
       "      <td>40.562222</td>\n",
       "      <td>-111.928889</td>\n",
       "      <td>(-120.0, -90.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80307</th>\n",
       "      <td>9/9/2012 21:00</td>\n",
       "      <td>oval</td>\n",
       "      <td>600.0</td>\n",
       "      <td>41.681944</td>\n",
       "      <td>-85.976667</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80308</th>\n",
       "      <td>9/9/2012 21:00</td>\n",
       "      <td>light</td>\n",
       "      <td>1290.0</td>\n",
       "      <td>40.714167</td>\n",
       "      <td>-74.006389</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80309</th>\n",
       "      <td>9/9/2012 21:00</td>\n",
       "      <td>oval</td>\n",
       "      <td>60.0</td>\n",
       "      <td>33.433056</td>\n",
       "      <td>-79.121667</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(18.0, 36.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80310</th>\n",
       "      <td>9/9/2012 21:00</td>\n",
       "      <td>circle</td>\n",
       "      <td>300.0</td>\n",
       "      <td>34.278333</td>\n",
       "      <td>-119.292222</td>\n",
       "      <td>(-120.0, -90.0]</td>\n",
       "      <td>(18.0, 36.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80311</th>\n",
       "      <td>9/9/2012 21:55</td>\n",
       "      <td>flash</td>\n",
       "      <td>900.0</td>\n",
       "      <td>32.776389</td>\n",
       "      <td>-79.931111</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(18.0, 36.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80312</th>\n",
       "      <td>9/9/2012 23:00</td>\n",
       "      <td>light</td>\n",
       "      <td>5.0</td>\n",
       "      <td>34.297778</td>\n",
       "      <td>-83.824167</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(18.0, 36.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80313</th>\n",
       "      <td>9/9/2013 00:15</td>\n",
       "      <td>unknown</td>\n",
       "      <td>1.0</td>\n",
       "      <td>36.846667</td>\n",
       "      <td>-76.285556</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80314</th>\n",
       "      <td>9/9/2013 01:50</td>\n",
       "      <td>triangle</td>\n",
       "      <td>180.0</td>\n",
       "      <td>42.886389</td>\n",
       "      <td>-78.878611</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80315</th>\n",
       "      <td>9/9/2013 03:00</td>\n",
       "      <td>unknown</td>\n",
       "      <td>120.0</td>\n",
       "      <td>41.052500</td>\n",
       "      <td>-80.608056</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80316</th>\n",
       "      <td>9/9/2013 09:51</td>\n",
       "      <td>light</td>\n",
       "      <td>4.0</td>\n",
       "      <td>32.715278</td>\n",
       "      <td>-117.156389</td>\n",
       "      <td>(-120.0, -90.0]</td>\n",
       "      <td>(18.0, 36.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80317</th>\n",
       "      <td>9/9/2013 12:34</td>\n",
       "      <td>cigar</td>\n",
       "      <td>8.0</td>\n",
       "      <td>30.505000</td>\n",
       "      <td>-97.820000</td>\n",
       "      <td>(-120.0, -90.0]</td>\n",
       "      <td>(18.0, 36.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80318</th>\n",
       "      <td>9/9/2013 13:10</td>\n",
       "      <td>unknown</td>\n",
       "      <td>90.0</td>\n",
       "      <td>53.250000</td>\n",
       "      <td>-113.783333</td>\n",
       "      <td>(-120.0, -90.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80319</th>\n",
       "      <td>9/9/2013 20:15</td>\n",
       "      <td>other</td>\n",
       "      <td>3600.0</td>\n",
       "      <td>40.858433</td>\n",
       "      <td>-74.163755</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80320</th>\n",
       "      <td>9/9/2013 20:20</td>\n",
       "      <td>fireball</td>\n",
       "      <td>60.0</td>\n",
       "      <td>33.209722</td>\n",
       "      <td>-87.569167</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(18.0, 36.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80321</th>\n",
       "      <td>9/9/2013 20:21</td>\n",
       "      <td>fireball</td>\n",
       "      <td>3.0</td>\n",
       "      <td>36.529722</td>\n",
       "      <td>-87.359444</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80322</th>\n",
       "      <td>9/9/2013 21:00</td>\n",
       "      <td>light</td>\n",
       "      <td>15.0</td>\n",
       "      <td>50.465843</td>\n",
       "      <td>22.891814</td>\n",
       "      <td>(0.0, 30.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80323</th>\n",
       "      <td>9/9/2013 21:00</td>\n",
       "      <td>triangle</td>\n",
       "      <td>60.0</td>\n",
       "      <td>29.651389</td>\n",
       "      <td>-82.325000</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(18.0, 36.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80324</th>\n",
       "      <td>9/9/2013 21:00</td>\n",
       "      <td>light</td>\n",
       "      <td>120.0</td>\n",
       "      <td>34.367594</td>\n",
       "      <td>-77.710548</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(18.0, 36.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80325</th>\n",
       "      <td>9/9/2013 21:00</td>\n",
       "      <td>fireball</td>\n",
       "      <td>180.0</td>\n",
       "      <td>46.300000</td>\n",
       "      <td>-63.216667</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80326</th>\n",
       "      <td>9/9/2013 21:00</td>\n",
       "      <td>sphere</td>\n",
       "      <td>20.0</td>\n",
       "      <td>34.101389</td>\n",
       "      <td>-84.519444</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(18.0, 36.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80327</th>\n",
       "      <td>9/9/2013 21:15</td>\n",
       "      <td>light</td>\n",
       "      <td>600.0</td>\n",
       "      <td>36.165833</td>\n",
       "      <td>-86.784444</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80328</th>\n",
       "      <td>9/9/2013 22:00</td>\n",
       "      <td>circle</td>\n",
       "      <td>1200.0</td>\n",
       "      <td>43.613611</td>\n",
       "      <td>-116.202500</td>\n",
       "      <td>(-120.0, -90.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80329</th>\n",
       "      <td>9/9/2013 22:00</td>\n",
       "      <td>other</td>\n",
       "      <td>1200.0</td>\n",
       "      <td>38.297222</td>\n",
       "      <td>-122.284444</td>\n",
       "      <td>(-150.0, -120.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80330</th>\n",
       "      <td>9/9/2013 22:20</td>\n",
       "      <td>circle</td>\n",
       "      <td>5.0</td>\n",
       "      <td>38.901111</td>\n",
       "      <td>-77.265556</td>\n",
       "      <td>(-90.0, -60.0]</td>\n",
       "      <td>(36.0, 54.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80331</th>\n",
       "      <td>9/9/2013 23:00</td>\n",
       "      <td>cigar</td>\n",
       "      <td>1020.0</td>\n",
       "      <td>35.652778</td>\n",
       "      <td>-97.477778</td>\n",
       "      <td>(-120.0, -90.0]</td>\n",
       "      <td>(18.0, 36.0]</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>80332 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "               datetime      shape  duration   latitude   longitude  \\\n",
       "0      10/10/1949 20:30   cylinder    2700.0  29.883056  -97.941111   \n",
       "1      10/10/1949 21:00      light    7200.0  29.384210  -98.581082   \n",
       "2      10/10/1955 17:00     circle      20.0  53.200000   -2.916667   \n",
       "3      10/10/1956 21:00     circle      20.0  28.978333  -96.645833   \n",
       "4      10/10/1960 20:00      light     900.0  21.418056 -157.803611   \n",
       "5      10/10/1961 19:00     sphere     300.0  36.595000  -82.188889   \n",
       "6      10/10/1965 21:00     circle     180.0  51.434722   -3.180000   \n",
       "7      10/10/1965 23:45       disk    1200.0  41.117500  -73.408333   \n",
       "8      10/10/1966 20:00       disk     180.0  33.586111  -86.286111   \n",
       "9      10/10/1966 21:00       disk     120.0  30.294722  -82.984167   \n",
       "10     10/10/1968 13:00     circle     300.0  33.916389 -118.351667   \n",
       "11     10/10/1968 19:00   fireball     180.0  35.233333  -82.734444   \n",
       "12     10/10/1970 16:00       disk    1800.0  40.668611  -73.527500   \n",
       "13     10/10/1970 19:00    unknown     180.0  37.153611  -83.761944   \n",
       "14     10/10/1971 21:00       oval      30.0  35.823889  -80.253611   \n",
       "15     10/10/1972 19:00     circle    1200.0  36.843056  -83.321944   \n",
       "16     10/10/1972 22:30       disk     120.0  42.537778  -83.233056   \n",
       "17     10/10/1973 19:00       disk    1800.0  41.325278  -72.193611   \n",
       "18     10/10/1973 23:00      light      20.0  32.364167  -64.678611   \n",
       "19     10/10/1974 19:30      other    2700.0  42.391667  -71.566667   \n",
       "20     10/10/1974 21:30       disk    1200.0  51.500000   -3.200000   \n",
       "21     10/10/1974 23:00      light    1200.0  38.105556  -98.659722   \n",
       "22     10/10/1975 17:00      light     360.0  32.854444  -79.975000   \n",
       "23     10/10/1976 20:30       oval      60.0  45.582778 -122.352222   \n",
       "24     10/10/1976 22:00      cigar       3.0  51.783333   -0.783333   \n",
       "25     10/10/1977 12:00      other      30.0  29.423889  -98.493333   \n",
       "26     10/10/1977 22:00      light      30.0  38.254167  -85.759444   \n",
       "27     10/10/1978 02:00  rectangle     300.0  40.700833  -73.713333   \n",
       "28     10/10/1979 00:00    chevron     900.0  41.700278  -73.921389   \n",
       "29     10/10/1979 22:00   triangle     270.0  53.970571 -111.689885   \n",
       "...                 ...        ...       ...        ...         ...   \n",
       "80302    9/9/2012 20:00      light   10800.0  35.721111  -77.915833   \n",
       "80303    9/9/2012 20:10     circle     600.0  40.700833  -73.713333   \n",
       "80304    9/9/2012 20:30      light     120.0  36.200000  -86.518611   \n",
       "80305    9/9/2012 20:30    chevron     900.0  34.278333 -119.292222   \n",
       "80306    9/9/2012 20:52     circle      10.0  40.562222 -111.928889   \n",
       "80307    9/9/2012 21:00       oval     600.0  41.681944  -85.976667   \n",
       "80308    9/9/2012 21:00      light    1290.0  40.714167  -74.006389   \n",
       "80309    9/9/2012 21:00       oval      60.0  33.433056  -79.121667   \n",
       "80310    9/9/2012 21:00     circle     300.0  34.278333 -119.292222   \n",
       "80311    9/9/2012 21:55      flash     900.0  32.776389  -79.931111   \n",
       "80312    9/9/2012 23:00      light       5.0  34.297778  -83.824167   \n",
       "80313    9/9/2013 00:15    unknown       1.0  36.846667  -76.285556   \n",
       "80314    9/9/2013 01:50   triangle     180.0  42.886389  -78.878611   \n",
       "80315    9/9/2013 03:00    unknown     120.0  41.052500  -80.608056   \n",
       "80316    9/9/2013 09:51      light       4.0  32.715278 -117.156389   \n",
       "80317    9/9/2013 12:34      cigar       8.0  30.505000  -97.820000   \n",
       "80318    9/9/2013 13:10    unknown      90.0  53.250000 -113.783333   \n",
       "80319    9/9/2013 20:15      other    3600.0  40.858433  -74.163755   \n",
       "80320    9/9/2013 20:20   fireball      60.0  33.209722  -87.569167   \n",
       "80321    9/9/2013 20:21   fireball       3.0  36.529722  -87.359444   \n",
       "80322    9/9/2013 21:00      light      15.0  50.465843   22.891814   \n",
       "80323    9/9/2013 21:00   triangle      60.0  29.651389  -82.325000   \n",
       "80324    9/9/2013 21:00      light     120.0  34.367594  -77.710548   \n",
       "80325    9/9/2013 21:00   fireball     180.0  46.300000  -63.216667   \n",
       "80326    9/9/2013 21:00     sphere      20.0  34.101389  -84.519444   \n",
       "80327    9/9/2013 21:15      light     600.0  36.165833  -86.784444   \n",
       "80328    9/9/2013 22:00     circle    1200.0  43.613611 -116.202500   \n",
       "80329    9/9/2013 22:00      other    1200.0  38.297222 -122.284444   \n",
       "80330    9/9/2013 22:20     circle       5.0  38.901111  -77.265556   \n",
       "80331    9/9/2013 23:00      cigar    1020.0  35.652778  -97.477778   \n",
       "\n",
       "                   long           lat  \n",
       "0       (-120.0, -90.0]  (18.0, 36.0]  \n",
       "1       (-120.0, -90.0]  (18.0, 36.0]  \n",
       "2          (-30.0, 0.0]  (36.0, 54.0]  \n",
       "3       (-120.0, -90.0]  (18.0, 36.0]  \n",
       "4      (-180.0, -150.0]  (18.0, 36.0]  \n",
       "5        (-90.0, -60.0]  (36.0, 54.0]  \n",
       "6          (-30.0, 0.0]  (36.0, 54.0]  \n",
       "7        (-90.0, -60.0]  (36.0, 54.0]  \n",
       "8        (-90.0, -60.0]  (18.0, 36.0]  \n",
       "9        (-90.0, -60.0]  (18.0, 36.0]  \n",
       "10      (-120.0, -90.0]  (18.0, 36.0]  \n",
       "11       (-90.0, -60.0]  (18.0, 36.0]  \n",
       "12       (-90.0, -60.0]  (36.0, 54.0]  \n",
       "13       (-90.0, -60.0]  (36.0, 54.0]  \n",
       "14       (-90.0, -60.0]  (18.0, 36.0]  \n",
       "15       (-90.0, -60.0]  (36.0, 54.0]  \n",
       "16       (-90.0, -60.0]  (36.0, 54.0]  \n",
       "17       (-90.0, -60.0]  (36.0, 54.0]  \n",
       "18       (-90.0, -60.0]  (18.0, 36.0]  \n",
       "19       (-90.0, -60.0]  (36.0, 54.0]  \n",
       "20         (-30.0, 0.0]  (36.0, 54.0]  \n",
       "21      (-120.0, -90.0]  (36.0, 54.0]  \n",
       "22       (-90.0, -60.0]  (18.0, 36.0]  \n",
       "23     (-150.0, -120.0]  (36.0, 54.0]  \n",
       "24         (-30.0, 0.0]  (36.0, 54.0]  \n",
       "25      (-120.0, -90.0]  (18.0, 36.0]  \n",
       "26       (-90.0, -60.0]  (36.0, 54.0]  \n",
       "27       (-90.0, -60.0]  (36.0, 54.0]  \n",
       "28       (-90.0, -60.0]  (36.0, 54.0]  \n",
       "29      (-120.0, -90.0]  (36.0, 54.0]  \n",
       "...                 ...           ...  \n",
       "80302    (-90.0, -60.0]  (18.0, 36.0]  \n",
       "80303    (-90.0, -60.0]  (36.0, 54.0]  \n",
       "80304    (-90.0, -60.0]  (36.0, 54.0]  \n",
       "80305   (-120.0, -90.0]  (18.0, 36.0]  \n",
       "80306   (-120.0, -90.0]  (36.0, 54.0]  \n",
       "80307    (-90.0, -60.0]  (36.0, 54.0]  \n",
       "80308    (-90.0, -60.0]  (36.0, 54.0]  \n",
       "80309    (-90.0, -60.0]  (18.0, 36.0]  \n",
       "80310   (-120.0, -90.0]  (18.0, 36.0]  \n",
       "80311    (-90.0, -60.0]  (18.0, 36.0]  \n",
       "80312    (-90.0, -60.0]  (18.0, 36.0]  \n",
       "80313    (-90.0, -60.0]  (36.0, 54.0]  \n",
       "80314    (-90.0, -60.0]  (36.0, 54.0]  \n",
       "80315    (-90.0, -60.0]  (36.0, 54.0]  \n",
       "80316   (-120.0, -90.0]  (18.0, 36.0]  \n",
       "80317   (-120.0, -90.0]  (18.0, 36.0]  \n",
       "80318   (-120.0, -90.0]  (36.0, 54.0]  \n",
       "80319    (-90.0, -60.0]  (36.0, 54.0]  \n",
       "80320    (-90.0, -60.0]  (18.0, 36.0]  \n",
       "80321    (-90.0, -60.0]  (36.0, 54.0]  \n",
       "80322       (0.0, 30.0]  (36.0, 54.0]  \n",
       "80323    (-90.0, -60.0]  (18.0, 36.0]  \n",
       "80324    (-90.0, -60.0]  (18.0, 36.0]  \n",
       "80325    (-90.0, -60.0]  (36.0, 54.0]  \n",
       "80326    (-90.0, -60.0]  (18.0, 36.0]  \n",
       "80327    (-90.0, -60.0]  (36.0, 54.0]  \n",
       "80328   (-120.0, -90.0]  (36.0, 54.0]  \n",
       "80329  (-150.0, -120.0]  (36.0, 54.0]  \n",
       "80330    (-90.0, -60.0]  (36.0, 54.0]  \n",
       "80331   (-120.0, -90.0]  (18.0, 36.0]  \n",
       "\n",
       "[80332 rows x 7 columns]"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "哪一个区域ufo事件多"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((-90.0, -60.0], (36.0, 54.0])        27891\n",
       "((-120.0, -90.0], (18.0, 36.0])       14280\n",
       "((-120.0, -90.0], (36.0, 54.0])       11960\n",
       "((-90.0, -60.0], (18.0, 36.0])         9923\n",
       "((-150.0, -120.0], (36.0, 54.0])       9658\n",
       "((-30.0, 0.0], (36.0, 54.0])           1967\n",
       "((0.0, 30.0], (36.0, 54.0])             847\n",
       "((-30.0, 0.0], (54.0, 72.0])            396\n",
       "((-150.0, -120.0], (54.0, 72.0])        396\n",
       "((-180.0, -150.0], (18.0, 36.0])        351\n",
       "((150.0, 180.0], (-36.0, -18.0])        259\n",
       "((60.0, 90.0], (18.0, 36.0])            194\n",
       "((30.0, 60.0], (18.0, 36.0])            188\n",
       "((-150.0, -120.0], (18.0, 36.0])        161\n",
       "((0.0, 30.0], (54.0, 72.0])             154\n",
       "((120.0, 150.0], (-54.0, -36.0])        150\n",
       "((120.0, 150.0], (-36.0, -18.0])        145\n",
       "((90.0, 120.0], (0.0, 18.0])            128\n",
       "((-90.0, -60.0], (0.0, 18.0])           101\n",
       "((150.0, 180.0], (-54.0, -36.0])         91\n",
       "((60.0, 90.0], (0.0, 18.0])              91\n",
       "((0.0, 30.0], (-36.0, -18.0])            86\n",
       "((-120.0, -90.0], (54.0, 72.0])          86\n",
       "((-60.0, -30.0], (-36.0, -18.0])         84\n",
       "((90.0, 120.0], (-36.0, -18.0])          77\n",
       "((-180.0, -150.0], (54.0, 72.0])         73\n",
       "((120.0, 150.0], (18.0, 36.0])           67\n",
       "((120.0, 150.0], (0.0, 18.0])            57\n",
       "((-60.0, -30.0], (36.0, 54.0])           47\n",
       "((30.0, 60.0], (36.0, 54.0])             41\n",
       "                                      ...  \n",
       "((-90.0, -60.0], (-36.0, -18.0])         25\n",
       "((0.0, 30.0], (18.0, 36.0])              21\n",
       "((-30.0, 0.0], (18.0, 36.0])             18\n",
       "((-120.0, -90.0], (0.0, 18.0])           17\n",
       "((-60.0, -30.0], (-18.0, 0.0])           15\n",
       "((90.0, 120.0], (-18.0, 0.0])            15\n",
       "((120.0, 150.0], (-18.0, 0.0])           14\n",
       "((90.0, 120.0], (36.0, 54.0])            14\n",
       "((-150.0, -120.0], (-18.0, 0.0])         14\n",
       "((-60.0, -30.0], (0.0, 18.0])            12\n",
       "((30.0, 60.0], (-18.0, 0.0])             10\n",
       "((60.0, 90.0], (36.0, 54.0])              9\n",
       "((0.0, 30.0], (0.0, 18.0])                8\n",
       "((30.0, 60.0], (0.0, 18.0])               5\n",
       "((60.0, 90.0], (-36.0, -18.0])            5\n",
       "((-30.0, 0.0], (0.0, 18.0])               4\n",
       "((-90.0, -60.0], (54.0, 72.0])            4\n",
       "((30.0, 60.0], (54.0, 72.0])              4\n",
       "((0.0, 30.0], (-18.0, 0.0])               3\n",
       "((-60.0, -30.0], (-54.0, -36.0])          3\n",
       "((150.0, 180.0], (-18.0, 0.0])            2\n",
       "((-90.0, -60.0], (72.0, 90.0])            2\n",
       "((-60.0, -30.0], (18.0, 36.0])            2\n",
       "((-90.0, -60.0], (-54.0, -36.0])          1\n",
       "((-120.0, -90.0], (-18.0, 0.0])           1\n",
       "((-180.0, -150.0], (36.0, 54.0])          1\n",
       "((-150.0, -120.0], (-90.0, -72.0])        1\n",
       "((-180.0, -150.0], (-36.0, -18.0])        1\n",
       "((-60.0, -30.0], (54.0, 72.0])            1\n",
       "((-120.0, -90.0], (-36.0, -18.0])         1\n",
       "Length: 65, dtype: int64"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#解题方式一\n",
    "pd.Series(list(zip(data['long'],data['lat']))).value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(Interval(-90.0, -60.0, closed='right'), Interval(36.0, 54.0, closed='right'))"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#解题方式二 将这两列设置成索引 统计哪一个索引出现的次数最高\n",
    "data.set_index(['long','lat']).index.value_counts().index[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "练习二"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>#</th>\n",
       "      <th>Name</th>\n",
       "      <th>Type 1</th>\n",
       "      <th>Type 2</th>\n",
       "      <th>Total</th>\n",
       "      <th>HP</th>\n",
       "      <th>Attack</th>\n",
       "      <th>Defense</th>\n",
       "      <th>Sp. Atk</th>\n",
       "      <th>Sp. Def</th>\n",
       "      <th>Speed</th>\n",
       "      <th>Generation</th>\n",
       "      <th>Legendary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>Bulbasaur</td>\n",
       "      <td>Grass</td>\n",
       "      <td>Poison</td>\n",
       "      <td>318</td>\n",
       "      <td>45</td>\n",
       "      <td>49</td>\n",
       "      <td>49</td>\n",
       "      <td>65</td>\n",
       "      <td>65</td>\n",
       "      <td>45</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>Ivysaur</td>\n",
       "      <td>Grass</td>\n",
       "      <td>Poison</td>\n",
       "      <td>405</td>\n",
       "      <td>60</td>\n",
       "      <td>62</td>\n",
       "      <td>63</td>\n",
       "      <td>80</td>\n",
       "      <td>80</td>\n",
       "      <td>60</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>Venusaur</td>\n",
       "      <td>Grass</td>\n",
       "      <td>Poison</td>\n",
       "      <td>525</td>\n",
       "      <td>80</td>\n",
       "      <td>82</td>\n",
       "      <td>83</td>\n",
       "      <td>100</td>\n",
       "      <td>100</td>\n",
       "      <td>80</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>VenusaurMega Venusaur</td>\n",
       "      <td>Grass</td>\n",
       "      <td>Poison</td>\n",
       "      <td>625</td>\n",
       "      <td>80</td>\n",
       "      <td>100</td>\n",
       "      <td>123</td>\n",
       "      <td>122</td>\n",
       "      <td>120</td>\n",
       "      <td>80</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>Charmander</td>\n",
       "      <td>Fire</td>\n",
       "      <td>NaN</td>\n",
       "      <td>309</td>\n",
       "      <td>39</td>\n",
       "      <td>52</td>\n",
       "      <td>43</td>\n",
       "      <td>60</td>\n",
       "      <td>50</td>\n",
       "      <td>65</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>Charmeleon</td>\n",
       "      <td>Fire</td>\n",
       "      <td>NaN</td>\n",
       "      <td>405</td>\n",
       "      <td>58</td>\n",
       "      <td>64</td>\n",
       "      <td>58</td>\n",
       "      <td>80</td>\n",
       "      <td>65</td>\n",
       "      <td>80</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6</td>\n",
       "      <td>Charizard</td>\n",
       "      <td>Fire</td>\n",
       "      <td>Flying</td>\n",
       "      <td>534</td>\n",
       "      <td>78</td>\n",
       "      <td>84</td>\n",
       "      <td>78</td>\n",
       "      <td>109</td>\n",
       "      <td>85</td>\n",
       "      <td>100</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>6</td>\n",
       "      <td>CharizardMega Charizard X</td>\n",
       "      <td>Fire</td>\n",
       "      <td>Dragon</td>\n",
       "      <td>634</td>\n",
       "      <td>78</td>\n",
       "      <td>130</td>\n",
       "      <td>111</td>\n",
       "      <td>130</td>\n",
       "      <td>85</td>\n",
       "      <td>100</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>6</td>\n",
       "      <td>CharizardMega Charizard Y</td>\n",
       "      <td>Fire</td>\n",
       "      <td>Flying</td>\n",
       "      <td>634</td>\n",
       "      <td>78</td>\n",
       "      <td>104</td>\n",
       "      <td>78</td>\n",
       "      <td>159</td>\n",
       "      <td>115</td>\n",
       "      <td>100</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>7</td>\n",
       "      <td>Squirtle</td>\n",
       "      <td>Water</td>\n",
       "      <td>NaN</td>\n",
       "      <td>314</td>\n",
       "      <td>44</td>\n",
       "      <td>48</td>\n",
       "      <td>65</td>\n",
       "      <td>50</td>\n",
       "      <td>64</td>\n",
       "      <td>43</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>8</td>\n",
       "      <td>Wartortle</td>\n",
       "      <td>Water</td>\n",
       "      <td>NaN</td>\n",
       "      <td>405</td>\n",
       "      <td>59</td>\n",
       "      <td>63</td>\n",
       "      <td>80</td>\n",
       "      <td>65</td>\n",
       "      <td>80</td>\n",
       "      <td>58</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>9</td>\n",
       "      <td>Blastoise</td>\n",
       "      <td>Water</td>\n",
       "      <td>NaN</td>\n",
       "      <td>530</td>\n",
       "      <td>79</td>\n",
       "      <td>83</td>\n",
       "      <td>100</td>\n",
       "      <td>85</td>\n",
       "      <td>105</td>\n",
       "      <td>78</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>9</td>\n",
       "      <td>BlastoiseMega Blastoise</td>\n",
       "      <td>Water</td>\n",
       "      <td>NaN</td>\n",
       "      <td>630</td>\n",
       "      <td>79</td>\n",
       "      <td>103</td>\n",
       "      <td>120</td>\n",
       "      <td>135</td>\n",
       "      <td>115</td>\n",
       "      <td>78</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>10</td>\n",
       "      <td>Caterpie</td>\n",
       "      <td>Bug</td>\n",
       "      <td>NaN</td>\n",
       "      <td>195</td>\n",
       "      <td>45</td>\n",
       "      <td>30</td>\n",
       "      <td>35</td>\n",
       "      <td>20</td>\n",
       "      <td>20</td>\n",
       "      <td>45</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>11</td>\n",
       "      <td>Metapod</td>\n",
       "      <td>Bug</td>\n",
       "      <td>NaN</td>\n",
       "      <td>205</td>\n",
       "      <td>50</td>\n",
       "      <td>20</td>\n",
       "      <td>55</td>\n",
       "      <td>25</td>\n",
       "      <td>25</td>\n",
       "      <td>30</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>12</td>\n",
       "      <td>Butterfree</td>\n",
       "      <td>Bug</td>\n",
       "      <td>Flying</td>\n",
       "      <td>395</td>\n",
       "      <td>60</td>\n",
       "      <td>45</td>\n",
       "      <td>50</td>\n",
       "      <td>90</td>\n",
       "      <td>80</td>\n",
       "      <td>70</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>13</td>\n",
       "      <td>Weedle</td>\n",
       "      <td>Bug</td>\n",
       "      <td>Poison</td>\n",
       "      <td>195</td>\n",
       "      <td>40</td>\n",
       "      <td>35</td>\n",
       "      <td>30</td>\n",
       "      <td>20</td>\n",
       "      <td>20</td>\n",
       "      <td>50</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>14</td>\n",
       "      <td>Kakuna</td>\n",
       "      <td>Bug</td>\n",
       "      <td>Poison</td>\n",
       "      <td>205</td>\n",
       "      <td>45</td>\n",
       "      <td>25</td>\n",
       "      <td>50</td>\n",
       "      <td>25</td>\n",
       "      <td>25</td>\n",
       "      <td>35</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>15</td>\n",
       "      <td>Beedrill</td>\n",
       "      <td>Bug</td>\n",
       "      <td>Poison</td>\n",
       "      <td>395</td>\n",
       "      <td>65</td>\n",
       "      <td>90</td>\n",
       "      <td>40</td>\n",
       "      <td>45</td>\n",
       "      <td>80</td>\n",
       "      <td>75</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>15</td>\n",
       "      <td>BeedrillMega Beedrill</td>\n",
       "      <td>Bug</td>\n",
       "      <td>Poison</td>\n",
       "      <td>495</td>\n",
       "      <td>65</td>\n",
       "      <td>150</td>\n",
       "      <td>40</td>\n",
       "      <td>15</td>\n",
       "      <td>80</td>\n",
       "      <td>145</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>16</td>\n",
       "      <td>Pidgey</td>\n",
       "      <td>Normal</td>\n",
       "      <td>Flying</td>\n",
       "      <td>251</td>\n",
       "      <td>40</td>\n",
       "      <td>45</td>\n",
       "      <td>40</td>\n",
       "      <td>35</td>\n",
       "      <td>35</td>\n",
       "      <td>56</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>17</td>\n",
       "      <td>Pidgeotto</td>\n",
       "      <td>Normal</td>\n",
       "      <td>Flying</td>\n",
       "      <td>349</td>\n",
       "      <td>63</td>\n",
       "      <td>60</td>\n",
       "      <td>55</td>\n",
       "      <td>50</td>\n",
       "      <td>50</td>\n",
       "      <td>71</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>18</td>\n",
       "      <td>Pidgeot</td>\n",
       "      <td>Normal</td>\n",
       "      <td>Flying</td>\n",
       "      <td>479</td>\n",
       "      <td>83</td>\n",
       "      <td>80</td>\n",
       "      <td>75</td>\n",
       "      <td>70</td>\n",
       "      <td>70</td>\n",
       "      <td>101</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>18</td>\n",
       "      <td>PidgeotMega Pidgeot</td>\n",
       "      <td>Normal</td>\n",
       "      <td>Flying</td>\n",
       "      <td>579</td>\n",
       "      <td>83</td>\n",
       "      <td>80</td>\n",
       "      <td>80</td>\n",
       "      <td>135</td>\n",
       "      <td>80</td>\n",
       "      <td>121</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>19</td>\n",
       "      <td>Rattata</td>\n",
       "      <td>Normal</td>\n",
       "      <td>NaN</td>\n",
       "      <td>253</td>\n",
       "      <td>30</td>\n",
       "      <td>56</td>\n",
       "      <td>35</td>\n",
       "      <td>25</td>\n",
       "      <td>35</td>\n",
       "      <td>72</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>20</td>\n",
       "      <td>Raticate</td>\n",
       "      <td>Normal</td>\n",
       "      <td>NaN</td>\n",
       "      <td>413</td>\n",
       "      <td>55</td>\n",
       "      <td>81</td>\n",
       "      <td>60</td>\n",
       "      <td>50</td>\n",
       "      <td>70</td>\n",
       "      <td>97</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>21</td>\n",
       "      <td>Spearow</td>\n",
       "      <td>Normal</td>\n",
       "      <td>Flying</td>\n",
       "      <td>262</td>\n",
       "      <td>40</td>\n",
       "      <td>60</td>\n",
       "      <td>30</td>\n",
       "      <td>31</td>\n",
       "      <td>31</td>\n",
       "      <td>70</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>22</td>\n",
       "      <td>Fearow</td>\n",
       "      <td>Normal</td>\n",
       "      <td>Flying</td>\n",
       "      <td>442</td>\n",
       "      <td>65</td>\n",
       "      <td>90</td>\n",
       "      <td>65</td>\n",
       "      <td>61</td>\n",
       "      <td>61</td>\n",
       "      <td>100</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>23</td>\n",
       "      <td>Ekans</td>\n",
       "      <td>Poison</td>\n",
       "      <td>NaN</td>\n",
       "      <td>288</td>\n",
       "      <td>35</td>\n",
       "      <td>60</td>\n",
       "      <td>44</td>\n",
       "      <td>40</td>\n",
       "      <td>54</td>\n",
       "      <td>55</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>24</td>\n",
       "      <td>Arbok</td>\n",
       "      <td>Poison</td>\n",
       "      <td>NaN</td>\n",
       "      <td>438</td>\n",
       "      <td>60</td>\n",
       "      <td>85</td>\n",
       "      <td>69</td>\n",
       "      <td>65</td>\n",
       "      <td>79</td>\n",
       "      <td>80</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>770</th>\n",
       "      <td>700</td>\n",
       "      <td>Sylveon</td>\n",
       "      <td>Fairy</td>\n",
       "      <td>NaN</td>\n",
       "      <td>525</td>\n",
       "      <td>95</td>\n",
       "      <td>65</td>\n",
       "      <td>65</td>\n",
       "      <td>110</td>\n",
       "      <td>130</td>\n",
       "      <td>60</td>\n",
       "      <td>6</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>771</th>\n",
       "      <td>701</td>\n",
       "      <td>Hawlucha</td>\n",
       "      <td>Fighting</td>\n",
       "      <td>Flying</td>\n",
       "      <td>500</td>\n",
       "      <td>78</td>\n",
       "      <td>92</td>\n",
       "      <td>75</td>\n",
       "      <td>74</td>\n",
       "      <td>63</td>\n",
       "      <td>118</td>\n",
       "      <td>6</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>772</th>\n",
       "      <td>702</td>\n",
       "      <td>Dedenne</td>\n",
       "      <td>Electric</td>\n",
       "      <td>Fairy</td>\n",
       "      <td>431</td>\n",
       "      <td>67</td>\n",
       "      <td>58</td>\n",
       "      <td>57</td>\n",
       "      <td>81</td>\n",
       "      <td>67</td>\n",
       "      <td>101</td>\n",
       "      <td>6</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>773</th>\n",
       "      <td>703</td>\n",
       "      <td>Carbink</td>\n",
       "      <td>Rock</td>\n",
       "      <td>Fairy</td>\n",
       "      <td>500</td>\n",
       "      <td>50</td>\n",
       "      <td>50</td>\n",
       "      <td>150</td>\n",
       "      <td>50</td>\n",
       "      <td>150</td>\n",
       "      <td>50</td>\n",
       "      <td>6</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>774</th>\n",
       "      <td>704</td>\n",
       "      <td>Goomy</td>\n",
       "      <td>Dragon</td>\n",
       "      <td>NaN</td>\n",
       "      <td>300</td>\n",
       "      <td>45</td>\n",
       "      <td>50</td>\n",
       "      <td>35</td>\n",
       "      <td>55</td>\n",
       "      <td>75</td>\n",
       "      <td>40</td>\n",
       "      <td>6</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>775</th>\n",
       "      <td>705</td>\n",
       "      <td>Sliggoo</td>\n",
       "      <td>Dragon</td>\n",
       "      <td>NaN</td>\n",
       "      <td>452</td>\n",
       "      <td>68</td>\n",
       "      <td>75</td>\n",
       "      <td>53</td>\n",
       "      <td>83</td>\n",
       "      <td>113</td>\n",
       "      <td>60</td>\n",
       "      <td>6</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>776</th>\n",
       "      <td>706</td>\n",
       "      <td>Goodra</td>\n",
       "      <td>Dragon</td>\n",
       "      <td>NaN</td>\n",
       "      <td>600</td>\n",
       "      <td>90</td>\n",
       "      <td>100</td>\n",
       "      <td>70</td>\n",
       "      <td>110</td>\n",
       "      <td>150</td>\n",
       "      <td>80</td>\n",
       "      <td>6</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>777</th>\n",
       "      <td>707</td>\n",
       "      <td>Klefki</td>\n",
       "      <td>Steel</td>\n",
       "      <td>Fairy</td>\n",
       "      <td>470</td>\n",
       "      <td>57</td>\n",
       "      <td>80</td>\n",
       "      <td>91</td>\n",
       "      <td>80</td>\n",
       "      <td>87</td>\n",
       "      <td>75</td>\n",
       "      <td>6</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>778</th>\n",
       "      <td>708</td>\n",
       "      <td>Phantump</td>\n",
       "      <td>Ghost</td>\n",
       "      <td>Grass</td>\n",
       "      <td>309</td>\n",
       "      <td>43</td>\n",
       "      <td>70</td>\n",
       "      <td>48</td>\n",
       "      <td>50</td>\n",
       "      <td>60</td>\n",
       "      <td>38</td>\n",
       "      <td>6</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>779</th>\n",
       "      <td>709</td>\n",
       "      <td>Trevenant</td>\n",
       "      <td>Ghost</td>\n",
       "      <td>Grass</td>\n",
       "      <td>474</td>\n",
       "      <td>85</td>\n",
       "      <td>110</td>\n",
       "      <td>76</td>\n",
       "      <td>65</td>\n",
       "      <td>82</td>\n",
       "      <td>56</td>\n",
       "      <td>6</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>780</th>\n",
       "      <td>710</td>\n",
       "      <td>PumpkabooAverage Size</td>\n",
       "      <td>Ghost</td>\n",
       "      <td>Grass</td>\n",
       "      <td>335</td>\n",
       "      <td>49</td>\n",
       "      <td>66</td>\n",
       "      <td>70</td>\n",
       "      <td>44</td>\n",
       "      <td>55</td>\n",
       "      <td>51</td>\n",
       "      <td>6</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>781</th>\n",
       "      <td>710</td>\n",
       "      <td>PumpkabooSmall Size</td>\n",
       "      <td>Ghost</td>\n",
       "      <td>Grass</td>\n",
       "      <td>335</td>\n",
       "      <td>44</td>\n",
       "      <td>66</td>\n",
       "      <td>70</td>\n",
       "      <td>44</td>\n",
       "      <td>55</td>\n",
       "      <td>56</td>\n",
       "      <td>6</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>782</th>\n",
       "      <td>710</td>\n",
       "      <td>PumpkabooLarge Size</td>\n",
       "      <td>Ghost</td>\n",
       "      <td>Grass</td>\n",
       "      <td>335</td>\n",
       "      <td>54</td>\n",
       "      <td>66</td>\n",
       "      <td>70</td>\n",
       "      <td>44</td>\n",
       "      <td>55</td>\n",
       "      <td>46</td>\n",
       "      <td>6</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>783</th>\n",
       "      <td>710</td>\n",
       "      <td>PumpkabooSuper Size</td>\n",
       "      <td>Ghost</td>\n",
       "      <td>Grass</td>\n",
       "      <td>335</td>\n",
       "      <td>59</td>\n",
       "      <td>66</td>\n",
       "      <td>70</td>\n",
       "      <td>44</td>\n",
       "      <td>55</td>\n",
       "      <td>41</td>\n",
       "      <td>6</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>784</th>\n",
       "      <td>711</td>\n",
       "      <td>GourgeistAverage Size</td>\n",
       "      <td>Ghost</td>\n",
       "      <td>Grass</td>\n",
       "      <td>494</td>\n",
       "      <td>65</td>\n",
       "      <td>90</td>\n",
       "      <td>122</td>\n",
       "      <td>58</td>\n",
       "      <td>75</td>\n",
       "      <td>84</td>\n",
       "      <td>6</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>785</th>\n",
       "      <td>711</td>\n",
       "      <td>GourgeistSmall Size</td>\n",
       "      <td>Ghost</td>\n",
       "      <td>Grass</td>\n",
       "      <td>494</td>\n",
       "      <td>55</td>\n",
       "      <td>85</td>\n",
       "      <td>122</td>\n",
       "      <td>58</td>\n",
       "      <td>75</td>\n",
       "      <td>99</td>\n",
       "      <td>6</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>786</th>\n",
       "      <td>711</td>\n",
       "      <td>GourgeistLarge Size</td>\n",
       "      <td>Ghost</td>\n",
       "      <td>Grass</td>\n",
       "      <td>494</td>\n",
       "      <td>75</td>\n",
       "      <td>95</td>\n",
       "      <td>122</td>\n",
       "      <td>58</td>\n",
       "      <td>75</td>\n",
       "      <td>69</td>\n",
       "      <td>6</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>787</th>\n",
       "      <td>711</td>\n",
       "      <td>GourgeistSuper Size</td>\n",
       "      <td>Ghost</td>\n",
       "      <td>Grass</td>\n",
       "      <td>494</td>\n",
       "      <td>85</td>\n",
       "      <td>100</td>\n",
       "      <td>122</td>\n",
       "      <td>58</td>\n",
       "      <td>75</td>\n",
       "      <td>54</td>\n",
       "      <td>6</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>788</th>\n",
       "      <td>712</td>\n",
       "      <td>Bergmite</td>\n",
       "      <td>Ice</td>\n",
       "      <td>NaN</td>\n",
       "      <td>304</td>\n",
       "      <td>55</td>\n",
       "      <td>69</td>\n",
       "      <td>85</td>\n",
       "      <td>32</td>\n",
       "      <td>35</td>\n",
       "      <td>28</td>\n",
       "      <td>6</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>789</th>\n",
       "      <td>713</td>\n",
       "      <td>Avalugg</td>\n",
       "      <td>Ice</td>\n",
       "      <td>NaN</td>\n",
       "      <td>514</td>\n",
       "      <td>95</td>\n",
       "      <td>117</td>\n",
       "      <td>184</td>\n",
       "      <td>44</td>\n",
       "      <td>46</td>\n",
       "      <td>28</td>\n",
       "      <td>6</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>790</th>\n",
       "      <td>714</td>\n",
       "      <td>Noibat</td>\n",
       "      <td>Flying</td>\n",
       "      <td>Dragon</td>\n",
       "      <td>245</td>\n",
       "      <td>40</td>\n",
       "      <td>30</td>\n",
       "      <td>35</td>\n",
       "      <td>45</td>\n",
       "      <td>40</td>\n",
       "      <td>55</td>\n",
       "      <td>6</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>791</th>\n",
       "      <td>715</td>\n",
       "      <td>Noivern</td>\n",
       "      <td>Flying</td>\n",
       "      <td>Dragon</td>\n",
       "      <td>535</td>\n",
       "      <td>85</td>\n",
       "      <td>70</td>\n",
       "      <td>80</td>\n",
       "      <td>97</td>\n",
       "      <td>80</td>\n",
       "      <td>123</td>\n",
       "      <td>6</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>792</th>\n",
       "      <td>716</td>\n",
       "      <td>Xerneas</td>\n",
       "      <td>Fairy</td>\n",
       "      <td>NaN</td>\n",
       "      <td>680</td>\n",
       "      <td>126</td>\n",
       "      <td>131</td>\n",
       "      <td>95</td>\n",
       "      <td>131</td>\n",
       "      <td>98</td>\n",
       "      <td>99</td>\n",
       "      <td>6</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>793</th>\n",
       "      <td>717</td>\n",
       "      <td>Yveltal</td>\n",
       "      <td>Dark</td>\n",
       "      <td>Flying</td>\n",
       "      <td>680</td>\n",
       "      <td>126</td>\n",
       "      <td>131</td>\n",
       "      <td>95</td>\n",
       "      <td>131</td>\n",
       "      <td>98</td>\n",
       "      <td>99</td>\n",
       "      <td>6</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>794</th>\n",
       "      <td>718</td>\n",
       "      <td>Zygarde50% Forme</td>\n",
       "      <td>Dragon</td>\n",
       "      <td>Ground</td>\n",
       "      <td>600</td>\n",
       "      <td>108</td>\n",
       "      <td>100</td>\n",
       "      <td>121</td>\n",
       "      <td>81</td>\n",
       "      <td>95</td>\n",
       "      <td>95</td>\n",
       "      <td>6</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>795</th>\n",
       "      <td>719</td>\n",
       "      <td>Diancie</td>\n",
       "      <td>Rock</td>\n",
       "      <td>Fairy</td>\n",
       "      <td>600</td>\n",
       "      <td>50</td>\n",
       "      <td>100</td>\n",
       "      <td>150</td>\n",
       "      <td>100</td>\n",
       "      <td>150</td>\n",
       "      <td>50</td>\n",
       "      <td>6</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>796</th>\n",
       "      <td>719</td>\n",
       "      <td>DiancieMega Diancie</td>\n",
       "      <td>Rock</td>\n",
       "      <td>Fairy</td>\n",
       "      <td>700</td>\n",
       "      <td>50</td>\n",
       "      <td>160</td>\n",
       "      <td>110</td>\n",
       "      <td>160</td>\n",
       "      <td>110</td>\n",
       "      <td>110</td>\n",
       "      <td>6</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>797</th>\n",
       "      <td>720</td>\n",
       "      <td>HoopaHoopa Confined</td>\n",
       "      <td>Psychic</td>\n",
       "      <td>Ghost</td>\n",
       "      <td>600</td>\n",
       "      <td>80</td>\n",
       "      <td>110</td>\n",
       "      <td>60</td>\n",
       "      <td>150</td>\n",
       "      <td>130</td>\n",
       "      <td>70</td>\n",
       "      <td>6</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>798</th>\n",
       "      <td>720</td>\n",
       "      <td>HoopaHoopa Unbound</td>\n",
       "      <td>Psychic</td>\n",
       "      <td>Dark</td>\n",
       "      <td>680</td>\n",
       "      <td>80</td>\n",
       "      <td>160</td>\n",
       "      <td>60</td>\n",
       "      <td>170</td>\n",
       "      <td>130</td>\n",
       "      <td>80</td>\n",
       "      <td>6</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>799</th>\n",
       "      <td>721</td>\n",
       "      <td>Volcanion</td>\n",
       "      <td>Fire</td>\n",
       "      <td>Water</td>\n",
       "      <td>600</td>\n",
       "      <td>80</td>\n",
       "      <td>110</td>\n",
       "      <td>120</td>\n",
       "      <td>130</td>\n",
       "      <td>90</td>\n",
       "      <td>70</td>\n",
       "      <td>6</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>800 rows × 13 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       #                       Name    Type 1  Type 2  Total   HP  Attack  \\\n",
       "0      1                  Bulbasaur     Grass  Poison    318   45      49   \n",
       "1      2                    Ivysaur     Grass  Poison    405   60      62   \n",
       "2      3                   Venusaur     Grass  Poison    525   80      82   \n",
       "3      3      VenusaurMega Venusaur     Grass  Poison    625   80     100   \n",
       "4      4                 Charmander      Fire     NaN    309   39      52   \n",
       "5      5                 Charmeleon      Fire     NaN    405   58      64   \n",
       "6      6                  Charizard      Fire  Flying    534   78      84   \n",
       "7      6  CharizardMega Charizard X      Fire  Dragon    634   78     130   \n",
       "8      6  CharizardMega Charizard Y      Fire  Flying    634   78     104   \n",
       "9      7                   Squirtle     Water     NaN    314   44      48   \n",
       "10     8                  Wartortle     Water     NaN    405   59      63   \n",
       "11     9                  Blastoise     Water     NaN    530   79      83   \n",
       "12     9    BlastoiseMega Blastoise     Water     NaN    630   79     103   \n",
       "13    10                   Caterpie       Bug     NaN    195   45      30   \n",
       "14    11                    Metapod       Bug     NaN    205   50      20   \n",
       "15    12                 Butterfree       Bug  Flying    395   60      45   \n",
       "16    13                     Weedle       Bug  Poison    195   40      35   \n",
       "17    14                     Kakuna       Bug  Poison    205   45      25   \n",
       "18    15                   Beedrill       Bug  Poison    395   65      90   \n",
       "19    15      BeedrillMega Beedrill       Bug  Poison    495   65     150   \n",
       "20    16                     Pidgey    Normal  Flying    251   40      45   \n",
       "21    17                  Pidgeotto    Normal  Flying    349   63      60   \n",
       "22    18                    Pidgeot    Normal  Flying    479   83      80   \n",
       "23    18        PidgeotMega Pidgeot    Normal  Flying    579   83      80   \n",
       "24    19                    Rattata    Normal     NaN    253   30      56   \n",
       "25    20                   Raticate    Normal     NaN    413   55      81   \n",
       "26    21                    Spearow    Normal  Flying    262   40      60   \n",
       "27    22                     Fearow    Normal  Flying    442   65      90   \n",
       "28    23                      Ekans    Poison     NaN    288   35      60   \n",
       "29    24                      Arbok    Poison     NaN    438   60      85   \n",
       "..   ...                        ...       ...     ...    ...  ...     ...   \n",
       "770  700                    Sylveon     Fairy     NaN    525   95      65   \n",
       "771  701                   Hawlucha  Fighting  Flying    500   78      92   \n",
       "772  702                    Dedenne  Electric   Fairy    431   67      58   \n",
       "773  703                    Carbink      Rock   Fairy    500   50      50   \n",
       "774  704                      Goomy    Dragon     NaN    300   45      50   \n",
       "775  705                    Sliggoo    Dragon     NaN    452   68      75   \n",
       "776  706                     Goodra    Dragon     NaN    600   90     100   \n",
       "777  707                     Klefki     Steel   Fairy    470   57      80   \n",
       "778  708                   Phantump     Ghost   Grass    309   43      70   \n",
       "779  709                  Trevenant     Ghost   Grass    474   85     110   \n",
       "780  710      PumpkabooAverage Size     Ghost   Grass    335   49      66   \n",
       "781  710        PumpkabooSmall Size     Ghost   Grass    335   44      66   \n",
       "782  710        PumpkabooLarge Size     Ghost   Grass    335   54      66   \n",
       "783  710        PumpkabooSuper Size     Ghost   Grass    335   59      66   \n",
       "784  711      GourgeistAverage Size     Ghost   Grass    494   65      90   \n",
       "785  711        GourgeistSmall Size     Ghost   Grass    494   55      85   \n",
       "786  711        GourgeistLarge Size     Ghost   Grass    494   75      95   \n",
       "787  711        GourgeistSuper Size     Ghost   Grass    494   85     100   \n",
       "788  712                   Bergmite       Ice     NaN    304   55      69   \n",
       "789  713                    Avalugg       Ice     NaN    514   95     117   \n",
       "790  714                     Noibat    Flying  Dragon    245   40      30   \n",
       "791  715                    Noivern    Flying  Dragon    535   85      70   \n",
       "792  716                    Xerneas     Fairy     NaN    680  126     131   \n",
       "793  717                    Yveltal      Dark  Flying    680  126     131   \n",
       "794  718           Zygarde50% Forme    Dragon  Ground    600  108     100   \n",
       "795  719                    Diancie      Rock   Fairy    600   50     100   \n",
       "796  719        DiancieMega Diancie      Rock   Fairy    700   50     160   \n",
       "797  720        HoopaHoopa Confined   Psychic   Ghost    600   80     110   \n",
       "798  720         HoopaHoopa Unbound   Psychic    Dark    680   80     160   \n",
       "799  721                  Volcanion      Fire   Water    600   80     110   \n",
       "\n",
       "     Defense  Sp. Atk  Sp. Def  Speed  Generation  Legendary  \n",
       "0         49       65       65     45           1      False  \n",
       "1         63       80       80     60           1      False  \n",
       "2         83      100      100     80           1      False  \n",
       "3        123      122      120     80           1      False  \n",
       "4         43       60       50     65           1      False  \n",
       "5         58       80       65     80           1      False  \n",
       "6         78      109       85    100           1      False  \n",
       "7        111      130       85    100           1      False  \n",
       "8         78      159      115    100           1      False  \n",
       "9         65       50       64     43           1      False  \n",
       "10        80       65       80     58           1      False  \n",
       "11       100       85      105     78           1      False  \n",
       "12       120      135      115     78           1      False  \n",
       "13        35       20       20     45           1      False  \n",
       "14        55       25       25     30           1      False  \n",
       "15        50       90       80     70           1      False  \n",
       "16        30       20       20     50           1      False  \n",
       "17        50       25       25     35           1      False  \n",
       "18        40       45       80     75           1      False  \n",
       "19        40       15       80    145           1      False  \n",
       "20        40       35       35     56           1      False  \n",
       "21        55       50       50     71           1      False  \n",
       "22        75       70       70    101           1      False  \n",
       "23        80      135       80    121           1      False  \n",
       "24        35       25       35     72           1      False  \n",
       "25        60       50       70     97           1      False  \n",
       "26        30       31       31     70           1      False  \n",
       "27        65       61       61    100           1      False  \n",
       "28        44       40       54     55           1      False  \n",
       "29        69       65       79     80           1      False  \n",
       "..       ...      ...      ...    ...         ...        ...  \n",
       "770       65      110      130     60           6      False  \n",
       "771       75       74       63    118           6      False  \n",
       "772       57       81       67    101           6      False  \n",
       "773      150       50      150     50           6      False  \n",
       "774       35       55       75     40           6      False  \n",
       "775       53       83      113     60           6      False  \n",
       "776       70      110      150     80           6      False  \n",
       "777       91       80       87     75           6      False  \n",
       "778       48       50       60     38           6      False  \n",
       "779       76       65       82     56           6      False  \n",
       "780       70       44       55     51           6      False  \n",
       "781       70       44       55     56           6      False  \n",
       "782       70       44       55     46           6      False  \n",
       "783       70       44       55     41           6      False  \n",
       "784      122       58       75     84           6      False  \n",
       "785      122       58       75     99           6      False  \n",
       "786      122       58       75     69           6      False  \n",
       "787      122       58       75     54           6      False  \n",
       "788       85       32       35     28           6      False  \n",
       "789      184       44       46     28           6      False  \n",
       "790       35       45       40     55           6      False  \n",
       "791       80       97       80    123           6      False  \n",
       "792       95      131       98     99           6       True  \n",
       "793       95      131       98     99           6       True  \n",
       "794      121       81       95     95           6       True  \n",
       "795      150      100      150     50           6       True  \n",
       "796      110      160      110    110           6       True  \n",
       "797       60      150      130     70           6       True  \n",
       "798       60      170      130     80           6       True  \n",
       "799      120      130       90     70           6       True  \n",
       "\n",
       "[800 rows x 13 columns]"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data= pd.read_csv('data/Pokemon.csv')\n",
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1:双属性的Pokemon占总体比例的多少"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5175"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['Type 2'].count()/data.shape[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2:在所有种族值（Total）不小于580(适合用query函数)的Pokemon中，非神兽（Legendary=False）的比例为多少？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.4247787610619469"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#解题方式一\n",
    "(data.query('(Total>=580)and (Legendary == False)')['Name'].count())/(data.query('(Total>=580)')['Name'].count())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True     0.575221\n",
       "False    0.424779\n",
       "Name: Legendary, dtype: float64"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#解题方式二\n",
    "data.query('Total >= 580')['Legendary'].value_counts(normalize =True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "在第一属性为格斗系（Fighting）的Pokemon中，物攻排名前三高的是哪些？\n",
    "iloc可按位置取"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>#</th>\n",
       "      <th>Name</th>\n",
       "      <th>Type 1</th>\n",
       "      <th>Type 2</th>\n",
       "      <th>Total</th>\n",
       "      <th>HP</th>\n",
       "      <th>Attack</th>\n",
       "      <th>Defense</th>\n",
       "      <th>Sp. Atk</th>\n",
       "      <th>Sp. Def</th>\n",
       "      <th>Speed</th>\n",
       "      <th>Generation</th>\n",
       "      <th>Legendary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>498</th>\n",
       "      <td>448</td>\n",
       "      <td>LucarioMega Lucario</td>\n",
       "      <td>Fighting</td>\n",
       "      <td>Steel</td>\n",
       "      <td>625</td>\n",
       "      <td>70</td>\n",
       "      <td>145</td>\n",
       "      <td>88</td>\n",
       "      <td>140</td>\n",
       "      <td>70</td>\n",
       "      <td>112</td>\n",
       "      <td>4</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>594</th>\n",
       "      <td>534</td>\n",
       "      <td>Conkeldurr</td>\n",
       "      <td>Fighting</td>\n",
       "      <td>NaN</td>\n",
       "      <td>505</td>\n",
       "      <td>105</td>\n",
       "      <td>140</td>\n",
       "      <td>95</td>\n",
       "      <td>55</td>\n",
       "      <td>65</td>\n",
       "      <td>45</td>\n",
       "      <td>5</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>74</th>\n",
       "      <td>68</td>\n",
       "      <td>Machamp</td>\n",
       "      <td>Fighting</td>\n",
       "      <td>NaN</td>\n",
       "      <td>505</td>\n",
       "      <td>90</td>\n",
       "      <td>130</td>\n",
       "      <td>80</td>\n",
       "      <td>65</td>\n",
       "      <td>85</td>\n",
       "      <td>55</td>\n",
       "      <td>1</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       #                 Name    Type 1 Type 2  Total   HP  Attack  Defense  \\\n",
       "498  448  LucarioMega Lucario  Fighting  Steel    625   70     145       88   \n",
       "594  534           Conkeldurr  Fighting    NaN    505  105     140       95   \n",
       "74    68              Machamp  Fighting    NaN    505   90     130       80   \n",
       "\n",
       "     Sp. Atk  Sp. Def  Speed  Generation  Legendary  \n",
       "498      140       70    112           4      False  \n",
       "594       55       65     45           5      False  \n",
       "74        65       85     55           1      False  "
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[data['Type 1']=='Fighting'].sort_values(by='Attack',ascending=False).iloc[:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(800, 14)"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "请问六项种族指标（HP、物攻、特攻、物防、特防、速度）极差的均值最大的是哪个属性（只考虑第一属性，且均值是对属性而言）？\n",
    "算的是每一行的均值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [],
   "source": [
    "data['range'] = data.iloc[:,5:11].max(axis=1)-data.iloc[:,5:11].min(axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [],
   "source": [
    "attribute = data[['Type 1','range']].set_index('Type 1')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Steel'"
      ]
     },
     "execution_count": 111,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#loc可传入索引子集构成的列表\n",
    "max_range = 0\n",
    "for i in attribute.index.unique():\n",
    "    #print(i)\n",
    "    temp = attribute.loc[i,:].mean()#得到所有同类型的均值\n",
    "    \n",
    "    if temp.values[0] > max_range:\n",
    "        max_range = temp.values[0]\n",
    "        result = i\n",
    "result\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "哪个属性（只考虑第一属性）的神兽比例最高？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Psychic'"
      ]
     },
     "execution_count": 118,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[data['Legendary']==True]['Type 1'].value_counts().index[0]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
